GridView中的行命令 [英] Row Command in GridView
本文介绍了GridView中的行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个显示和下载文件的gridview.但是,当我单击下载按钮时,什么都没有发生..gridview是:
I have a gridview to display and download files.But when i click on the download button nothing happens..the gridview is:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" PageIndex="5" PageSize="5"
style="margin-left: 312px; margin-top: 20px;" HorizontalAlign="Justify"
onselectedindexchanged="GridView2_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="File_Name" HeaderText="File Name"
SortExpression="File_Name" />
<asp:BoundField DataField="Document_Number" HeaderText="Document Number"
SortExpression="Document_Number" />
<asp:BoundField DataField="Upload_Date" HeaderText="Uploaded On"
SortExpression="UploadDate" />
<asp:BoundField DataField="Upload_User" HeaderText="Uploaded BY"
SortExpression="Upload_User" />
<asp:ButtonField ButtonType="Link" CommandName="Dwn" Text="Download"
HeaderText="Download Files"/>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
而rowcommad是
and the rowcommad is
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Dwn")
{
string path = ("NewFolder1") + "\\" +ddcollege.SelectedValue + "\\" + dddept.SelectedValue + "\\"
+ddcategory.SelectedValue + "\\" + ddloctn.SelectedItem + "\\";
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView2.Rows[index];
string fName = row.Cells[1].Text;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fName);
Response.TransmitFile(Server.MapPath(path+ fName));
Response.End();
}
}
关于y的任何想法.我什至尝试调试它,但是在单击按钮时..未达到行数.
谢谢
any idea as to y.I even tried to debug it but upon clicking the button..the lines are not reached.
Thanks
推荐答案
没有为您的网格指定行命令,您必须添加它..
OnRowCommand ="GridView2_RowCommand"
There is no row command specified for you grid you have to add this..
OnRowCommand="GridView2_RowCommand"
是的,在网格视图代码中未指定行命令,并且您还没有传递CommandArgument.就像下面的
CommandName ="Dwn" CommandArgument = value
Yaa right Row Command is not specified in your gridview code & also you have not passed CommandArgument. Just like below
CommandName="Dwn" CommandArgument=value
这篇关于GridView中的行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文