PDA

View Full Version : مبتدی: گذاشتن لینک دانلود فایل در گرید در رخداد select



monire.6767
دوشنبه 30 اردیبهشت 1392, 11:52 صبح
سلام
من یه گرید دارم که یه لینک دانلود داره هر سطر با کلیک روی آن میخوام تاریخ دریافت رو وارد کنم و همچنین صفحه باز شه برای دانلود کاربر
این کدمه


<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="False"
BackColor="White" OnRowCommand="gvList_RowCommand" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="id_file" DataSourceID="SqlDataSource1" Width="90%"
CssClass="mGrid" AllowPaging="True" AllowSorting="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("img") %>' />
</ItemTemplate>
<ControlStyle Height="36px" Width="35px" />
<ItemStyle Height="36px" Width="35px" />
</asp:TemplateField>
<asp:BoundField DataField="date_Recipient" HeaderText="تاريخ دريافت"
SortExpression="date_Recipient" >
<HeaderStyle ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="date_send" HeaderText="تاريخ ارسال"
SortExpression="date_send" >
<HeaderStyle ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="name_Sender" HeaderText="نام فرستنده"
SortExpression="name_Sender" >
<HeaderStyle ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="name_Recipient" HeaderText="نام گيرنده"
SortExpression="name_Recipient" >
<HeaderStyle ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="name_file" HeaderText="نام اصلي فايل" SortExpression="name_file" >
<HeaderStyle ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="fileZip" HeaderText="فايل"
SortExpression="fileZip" >
<HeaderStyle ForeColor="White" />
</asp:BoundField>
<asp:BoundField DataField="content" HeaderText="حجم"
SortExpression="content" />

<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Select" CommandArgument='<%# Eval("id_file") %>' PostBackUrl='<%# Eval("fileZip","zip/{0}") %>'><%# Eval("fileZip") %></asp:LinkButton>
<%-- <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("fileZip","zip/{0}") %>'
Text='<%# Eval("fileZip") %>' ></asp:HyperLink>--%>

</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Image" DeleteImageUrl="~/img/DeleteRed.png"
ShowDeleteButton="True" />



</Columns>
<RowStyle BackColor="#EAEAEA" ForeColor="#333333" />
<FooterStyle BackColor="black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="White"
HorizontalAlign="Center"
VerticalAlign="Middle" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EmptyDataTemplate>
رکوردی وجود ندارد
</EmptyDataTemplate>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TransferConnectionString %>"

SelectCommand="SELECT * FROM [tb_file] WHERE ([id_Recipient] = @id_Recipient)">
<SelectParameters>
<asp:SessionParameter Name="id_Recipient" SessionField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>





protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
{

switch (e.CommandName.ToString())
{
case "Select":
EditRecord(Convert.ToInt32(e.CommandArgument));
break;
default: break;
}


}
protected void EditRecord(int id)
{

FileTransferDataContext db = new FileTransferDataContext();
gvList.EditIndex = -1;


var itemTable = from p in db.tb_files
where p.id_file == id
select p;
foreach (var item in itemTable)
{

item.date_Recipient = Persia.Calendar.ConvertToPersian(DateTime.Now).Sim ple;
item.flag = 0;
item.img = "img/massege2.png";

}
db.SubmitChanges();

gvList.DataBind();


}

monire.6767
دوشنبه 30 اردیبهشت 1392, 13:46 عصر
چرا کسی راهنماییم نمیکنه :ناراحت: