如何在GridView中获取选定的行和列值 [英] how to get selected row and column value in gridview

查看:132
本文介绍了如何在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

推荐答案

帮我解决这个问题,请先尝试我的文章,然后再找我.我认为您应该使用HyperlinkField.请参阅以下链接.如果可行,请不要忘记将其添加为书签,因为这是逐步进行的操作


在ASP.NET中的GridView中创建HyperLinkField的实用指南 [
First try my article and then get back to me. I think you should take HyperlinkField. See the following link. If that works, please do not forget to bookmark the same as it is a step step by process


Practical Guide for Creating HyperLinkField in GridView in ASP.NET[^]


protected void gvScreenLayout_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          int rowIndex = Convert.ToInt32(e.CommandArgument);
          HyperLink hyperlink = (HyperLink)gvScreenLayout.Rows[rowIndex].FindControl("HyperLink1");
      }


这篇关于如何在GridView中获取选定的行和列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆