<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
CellPadding="4">
<Columns>
<asp:BoundField DataField="FileID" HeaderText="FileID" />
<asp:BoundField DataField="FilePath" HeaderText="FilePath" />
<asp:BoundField DataField="UploadedBy" HeaderText="CreatedBy" />
<asp:BoundField DataField="CreatedDate" HeaderText="CreatedDate" />
<asp:HyperLinkField HeaderText="LINK" NavigateUrl="show.aspx" Text="SHOW" />
</Columns>
conn.Open();
SqlDataReader rdr = comm.ExecuteReader();
if (NAME.Equals("admin"))
{
GridView1.DataSource = rdr;
GridView1.DataBind();
}
else
{
GridView2.DataSource = rdr;
GridView2.DataBind();
}
rdr.Close();
我想使用Gridview中的超链接根据点击的行动态传递值。由于我是新手,我无法做到这一点。请任何人帮助我。
答案 0 :(得分:2)
将hyperlink NavigateUrl
属性设置为... NavigateUrl='<%# Eval("FileID", "show.aspx?ID={0}" %>'
NavigateUrl='<%# Eval("FileID", "show.aspx?ID={0}") + "&FilePath=" + Eval("FilePath") %>'
答案 1 :(得分:1)
在网格中添加onRowCommand事件
OnRowCommand="OnRowCommand_GridView1"
然后使用CommandName和CommandArgument
定义链接Button <asp:LinkButton ID="lnk1" runat="server" Text="DoClick" CommandName="Select" CommandArgument='<%#Eval("FileID") %>'></asp:LinkButton>
而不是背后的代码
protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int MyFileID = e.CommandArgument;
//Now Perfrom here ur desired action
}
希望这会对你有所帮助。
答案 2 :(得分:0)
检查GridView的RowCommand
检查以下链接: How to get the current row in GridView Row Command Event?
有关行命令的信息:GridView.RowCommand Event