views:

55

answers:

1

I have a Gridview

<asp:GridView ID="GridView1" runat="server" Width="400px" AutoGenerateColumns="false"
            OnSelectedIndexChanged="GridView1_SelectedIndexChanged1">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBox1" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="name">
                    <ItemTemplate>
                        <asp:Label ID="lblStudentName" runat="server" Text='<%# Eval("StudentName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Address">
                    <ItemTemplate>
                        <asp:Label ID="lblResidentialAddress" runat="server" Text='<%# Eval("ResidentialAddress") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>
        </asp:GridView>

and i get the value binded to the gridview

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {

        DataTable dt = new DataTable();
        dt = objdb.GetData("Getsamples", new object[] { });
        ViewState["CurrentTable"] = dt;
        GridView1.DataSource = dt;

        GridView1.DataBind();

    }
}

protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
    Response.Write(GridView1.SelectedRow.Cells[0].Text); 
  //  string selectedText = ((Label)GridView1.SelectedRow.FindControl("lblStudentName")).Text;

  //  Response.Write(selectedText);
}

i cannot able to retrive the row where the checkbox is checked...

How to select particular row in a gridview, and based upon the selection i need to take out the 'Name' and pass this as a parameter to get ,another gridview related to the row which i selected.???

any help...

A: 

Try using another event - OnSelectedIndexChanging (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanging.aspx)

It has GridViewSelectEventArgs (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewselecteventargs_members.aspx) passed to the event handler which has NewSelectedIndex property.

Your event handler will look like:

void GridView1_SelectedIndexChanging(Object sender, GridViewSelectEventArgs e)
{
     GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
}
Andrew Bezzub