Click here to Skip to main content
16,008,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i've three template fields and one is hyperlink1,second is ImageButton1 ,third is InageButton2.
XML
<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

C#
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
Posted
Updated 14-Jul-11 0:14am
v2

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[^]
 
Share this answer
 
Comments
ks ravi 14-Jul-11 6:42am    
thanks for reply but i do not think this answer is relavent to my question plz help me out in my error
C#
protected void gvScreenLayout_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          int rowIndex = Convert.ToInt32(e.CommandArgument);
          HyperLink hyperlink = (HyperLink)gvScreenLayout.Rows[rowIndex].FindControl("HyperLink1");
      }
 
Share this answer
 
Comments
ks ravi 15-Jul-11 0:05am    
thanks for reply .I've tried with this also but not helping.if i use Rows[rowIndex]and if rowIndex=5,it will show hyperlink.Text=E(according to my thing)but should come like 'A' as clicked on first row.Plz reply
DipaliKolhe 15-Jul-11 1:10am    
I am not clear with your requirement? can elaborate please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900