GridView TemplateField 中的LinkButton命令怎么取得当前行的索引?
GridView TemplateField 中的LinkButton命令怎么取得当前行的索引?
如题。
<EditItemTemplate>
<asp:LinkButton ID= "linkbtn " runat= "server " Text = ' <%#Eval( "IsLock ").ToString()== "0 "? "禁止 ": "通过 " %> ' OnClick= "linkbtn_Click "> '> </asp:LinkButton>
</EditItemTemplate>
点OnClick 处理事件时候需要当前行的索引?怎么取?
------解决方案--------------------protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
LinkButton lb = (LinkButton)sender;
DataControlFieldCell dcf = (DataControlFieldCell)lb.Parent;
GridViewRow gvr = (GridViewRow)dcf.Parent;
GridView1.SelectedIndex = gvr.RowIndex;
}
应该是你要的吧?
------解决方案--------------------在邦定时把当前的索引加到LinkButton 的CommandArgument
然后用
e.CommandArgument就可取到当前的索引
------解决方案--------------------LinkButton中加入CommandName= "Edit " CommandArgument= " <%# Eval( "id ")%> "属性,然后在
protected void LinkButton1_Command(object sender, CommandEventArgs e)
{
if(e.CommandName== "Edit ")
{
XXXX;
}
}