本文介绍了如何在GridView中获取选定的行和列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有三个模板字段,一个是超链接1,第二个是ImageButton1,第三个是InageButton2.
Hi All,
i''ve three template fields and one is hyperlink1,second is ImageButton1 ,third is InageButton2.
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# Eval("RowName") %>' runat="server"></asp:HyperLink>
</ItemTemplate>
<ItemStyle BorderStyle="None" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" CommandArgument='<%# Eval("1") %>' CommandName="ib1"
Visible='<%# MyVisible(Eval("1").ToString()) %>' runat="server" ImageUrl="~/images/wchair.jpg" />
</ItemTemplate>
<ItemStyle BorderStyle="None" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton2" runat="server" CommandArgument='<%# Eval("2") %>'
CommandName="ib2" Visible='<%# MyVisible(Eval("2").ToString()) %>' ImageUrl="~/images/wchair.jpg" />
</ItemTemplate>
<ItemStyle BorderStyle="None" />
</asp:TemplateField>
在服务器端,我想获取行值,即超链接文本.为此,我使用了以下代码
In server side i want to get row value ie hyperlink text.For that i''ve used follwing code
protected void gvScreenLayout_RowCommand(object sender, GridViewCommandEventArgs e)
{
int ColumnIndex = Convert.ToInt32(e.CommandName);//this is fine
HyperLink col = (HyperLink)gvScreenLayout.SelectedRow.FindControl("HyperLink1");//Error:Object is not set to an instance
string columnindex = col.Text;
}
但是抱歉,这不起作用.请使用示例
But Sorry this is not working.Please help me out in this with examples
推荐答案
protected void gvScreenLayout_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
HyperLink hyperlink = (HyperLink)gvScreenLayout.Rows[rowIndex].FindControl("HyperLink1");
}
这篇关于如何在GridView中获取选定的行和列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!