Click here to Skip to main content
15,921,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a gridview as
<asp:UpdatePanel ID="UpdatePanel3" runat="server">

            <ContentTemplate>
                <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" ShowFooter="True"
                    OnPageIndexChanging="GridView1_PageIndexChanging" Style="table-layout: fixed;"
                    CssClass="mGrid" DataKeyNames="AreaID" PagerStyle-CssClass="pgr" ShowHeader="False"
                    AlternatingRowStyle-CssClass="alt" Width="652px" Height="625px" OnRowDataBound="GridView1_RowDataBound"
                    OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                    <%-- <BoundaryStyle BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px" />--%>
                    <AlternatingRowStyle CssClass="alt" />
                    <Columns>
                        <asp:TemplateField ItemStyle-Width="43px">
                            <ItemTemplate>
                                <%#Container.DataItemIndex+1 %>
                            </ItemTemplate>
                            <ItemStyle Width="43px" />
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="ID" DataField="AreaID" HeaderStyle-HorizontalAlign="Left"
                            Visible="false">
                            <HeaderStyle HorizontalAlign="Left" />
                        </asp:BoundField>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName=""
                                    Text='<%# Eval("Area") %>'></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <PagerStyle Font-Names="Calibri" Font-Size="12px" Width="303px" BackColor="#000000"
                        HorizontalAlign="Center" ForeColor="White" />
                </asp:GridView>


                   <asp:Button ID="btnTest"  runat="server"  onclick="gridview_click" />
            </ContentTemplate>
        </asp:UpdatePanel>


my aspx.cs code as
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
     if (e.Row.RowType == DataControlRowType.DataRow)
          {
              e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ceedfc'");
              e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
              e.Row.Attributes.Add("style", "cursor:pointer;");
              //e.Row.Attributes.Add("onclick", "location='patron_detail.aspx?id=" + e.Row.Cells[0].Text + "'");
              e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackClientHyperlink(btnTest, , e.Row.RowIndex.ToString());
          }

      }

 protected void GridView1_OnClick(object sender, EventArgs e){

       //{
       btnNew.Visible = false;
       btnUpdate.Visible = true;
       this.ModalPopupExtender1.Show();

   }

        public class btnTest : Button, IPostBackEventHandler
   {

       // Use the constructor to defined default label text.
       public btnTest()
       {
       }

       // Implement the RaisePostBackEvent method from the
       // IPostBackEventHandler interface.
       public void RaisePostBackEvent(string eventArgument)
       {
           //You receive the row number here.
       }
   }


My Popup is getting opened, but i am not able to find selected rowindex of the gridview, how to find this.??.What wrong in my code.
Posted
Updated 6-Nov-12 23:31pm
v2
Comments
NAPorwal(8015059) 7-Nov-12 5:28am    
when this GridView1_OnClick() is getting called in which u r opening popup?
sanrai 7-Nov-12 5:34am    
yes on gridview_onclick() i m opening popup,when gridview row is click by user.
NAPorwal(8015059) 7-Nov-12 5:51am    
if inside gridview_onclick() u can open popup and problem is only to the clicked row... then u can use this .. hope it'll help



Button btnObj = (Button)sender;
GridViewRow row = (GridViewRow)btnObj.NamingContainer;

this will return the selected row and then u can find any control inside this
using below code.

row.FindControl()

1 solution

try this...

Button btnObj = (Button)sender;
GridViewRow row = (GridViewRow)btnObj.NamingContainer;
 
Share this answer
 

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