PDA

View Full Version : سوال: قرار دادن لینک دانلود در گرید؟



پیام حیاتی
دوشنبه 21 دی 1394, 19:12 عصر
سلام
می خوام فایل های ضمیمه ارسالی از فرم رو در یکی از فیلدهای گرید نمایش بدم به طوری که با کلیک بر روی آن دانلود بشه؟

138319

یک BoundField به ستون های گرید اضافه کردم و DataField رو برابر نام ستون جدول که نام فایل ها در آن قرار دارد ، قرار دادم.(فایل های در پوشه ذخیره شده می شوند و فقط نام آنها در بانک قرار می گیرد.)


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="rep_id" HeaderText="شماره" />
<asp:ButtonField DataTextField="rep_upload" HeaderText="ضمیمه" Text="Button" />

</Columns>
</asp:GridView>


نتیجه :

138320

چه کدی باید قرار بدم که با کلیک بر روی نام فایل در گرید ، فایل مربوطه در پوشه دانلود شود؟
تشکر

پیام حیاتی
سه شنبه 22 دی 1394, 14:37 عصر
بروزرسانی.....

komeil64
سه شنبه 22 دی 1394, 14:48 عصر
یک itemtemplate توی گردتون ایجاد کنید و توش کد زیر رو قرار بدیم
<a href="address/<%# Eval("rep_upload") %>"><%# Eval("rep_upload") %></a>

پیام حیاتی
سه شنبه 22 دی 1394, 18:20 عصر
<asp:TemplateField HeaderText="دانلود">
<a href="Report/<%# Eval("rep_upload") %>"><%# Eval("rep_upload") %></a>
</asp:TemplateField>



Server Error in '/' Application.


Parser Error


Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.


Parser Error Message: Content ('<a href="Report/') does not match any properties within a 'System.Web.UI.WebControls.TemplateField', make sure it is well-formed.


Source Error:




Line 298: <asp:ButtonField DataTextField="rep_upload" HeaderText="تست" Text="Button" />
Line 299: <asp:TemplateField HeaderText="دانلود">
Line 300: <a href="Report/<%# Eval("rep_upload") %>"><%# Eval("rep_upload") %></a>
Line 301: </asp:TemplateField>
Line 302:

پیام حیاتی
چهارشنبه 23 دی 1394, 12:10 عصر
بروزرسانی....

پیام حیاتی
پنج شنبه 24 دی 1394, 20:09 عصر
عجب....
یعنی هیچ کس تا حالا اینکار رو انجام نداده ؟!

xsbehx
پنج شنبه 24 دی 1394, 21:54 عصر
به جای اون تگ a یک دکمه asp بنداز . یک دکمه معمولی یا imagebutton یا ...


<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnUpdate" Text="<%# Eval("rep_upload")%>" runat="server" CommandArgument='<%# Eval("PrimaryKey") %>' />
</ItemTemplate>
</asp:TemplateField>

به جای PrimaryKey تو بالا اسم فیلدی که کلید اصلی رو بزار.

حالا برو تو event یا رویداد RowCommand گریدویو یک select بنویس
تو این event شما اگر بنویسی e.CommandArgument بهت کلید اصلی اون سطری رو می ده که کلیک شده
حالا شما بر اساس کلید اصلی که کلید شده، یه دستور select می زنی که فیلدی که توش مسیر فایلت یا همون rep_upload رو نگهداشتی بدست بیاری
مثلا این یک دستور select تو سی شارپه!:


var YourLink = select rep_upload from tblTest
where PrimaryKey = e.CommandArgment

در انتها هم بنویس


Response.Redirect(YourLink);

ببین درست کار می کنه یا نه

پیام حیاتی
پنج شنبه 24 دی 1394, 23:48 عصر
به جای اون تگ a یک دکمه asp بنداز . یک دکمه معمولی یا imagebutton یا ...


<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnUpdate" Text="<%# Eval("rep_upload")%>" runat="server" CommandArgument='<%# Eval("PrimaryKey") %>' />
</ItemTemplate>
</asp:TemplateField>

به جای PrimaryKey تو بالا اسم فیلدی که کلید اصلی رو بزار.

حالا برو تو event یا رویداد RowCommand گریدویو یک select بنویس
تو این event شما اگر بنویسی e.CommandArgument بهت کلید اصلی اون سطری رو می ده که کلیک شده
حالا شما بر اساس کلید اصلی که کلید شده، یه دستور select می زنی که فیلدی که توش مسیر فایلت یا همون rep_upload رو نگهداشتی بدست بیاری
مثلا این یک دستور select تو سی شارپه!:


var YourLink = select rep_upload from tblTest
where PrimaryKey = e.CommandArgment

در انتها هم بنویس


Response.Redirect(YourLink);

ببین درست کار می کنه یا نه

دیزاین :


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" >


<Columns>
<asp:TemplateField HeaderText="فایل">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="<%# Eval("rep_upload")%>" CommandArgument='<%# Eval("rep_id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>


</asp:GridView>


کد سی شارپ :


string result = "SELECT rep_upload FROM Report WHERE rep_id= '" + e.CommandArgument + "' ";
SqlCommand bingo = new SqlCommand(result, con);
con.Open();
Response.Redirect(result);
con.Close();


خطا :


Server Error in '/' Application.


Parser Error


Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.


Parser Error Message: The server tag is not well formed.


Source Error:




Line 298: <asp:TemplateField HeaderText="فایل">
Line 299: <ItemTemplate>
Line 300: <asp:Button ID="Button1" runat="server" Text="<%# Eval("rep_upload")%>" CommandArgument='<%# Eval("rep_id") %>' />
Line 301: </ItemTemplate>
Line 302: </asp:TemplateField>

xsbehx
جمعه 25 دی 1394, 00:13 صبح
خوب عزیزم معلومه که چرا خطا می ده (حالا خودم 10 دقیقه است دارم فکر م کنم ^_^)
دستور قبلی رو هم که دوستمون داده بود رو هم همینکارو بکن درست می شه
روش ایشون بهتر از روش منه
اینو


Text="<%# Eval("rep_upload")%>"

تبدیل کن به این


Text='<%# Eval("rep_upload")%>'

پیام حیاتی
جمعه 25 دی 1394, 13:35 عصر
خوب عزیزم معلومه که چرا خطا می ده (حالا خودم 10 دقیقه است دارم فکر م کنم ^_^)
دستور قبلی رو هم که دوستمون داده بود رو هم همینکارو بکن درست می شه
روش ایشون بهتر از روش منه
اینو


Text="<%# Eval("rep_upload")%>"

تبدیل کن به این


Text='<%# Eval("rep_upload")%>'

زمانی که بر روی نام فایل کلیک می کنیم ، مسیر رو پیدا نمی کنه :


Server Error in '/' Application.


The resource cannot be found.


Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.


Requested URL: /SELECT rep_upload FROM Report WHERE rep_id= '4'




روش دوستمون رو هر چقدر با این علائم ' " سروکله زدم نشد.


<Columns>
<asp:TemplateField HeaderText="دانلود">
<a href="Report/">'<%# Eval("rep_upload") %>'>'<%# Eval("rep_upload") %>'</a>
</asp:TemplateField>
</Columns>

xsbehx
شنبه 26 دی 1394, 03:07 صبح
اینو تست گن


<a href='<%# String.Format("Report/{0}", Eval("rep_upload") %>'>

پیام حیاتی
شنبه 26 دی 1394, 08:27 صبح
اینو تست گن


<a href='<%# String.Format("Report/{0}", Eval("rep_upload") %>'>




Parser Error


Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.


Parser Error Message: Type 'System.Web.UI.WebControls.TemplateField' does not have a public property named 'a'.

پیام حیاتی
دوشنبه 28 دی 1394, 20:55 عصر
بروزررسانی......