Dear All, I have a Main GridView with a Nested GridView data. I want to retrieve the Nested GridView data based on main GridView ID and Button Click. if the Main GridView ID has a Session value "Yes" then display the Nested GridView with its data on Button Click.
HTML CODE:
<asp:TextBox ID="MyConferenceID" runat="server" Width="50px"> </asp:TextBox>
<asp:Button ID="KonferanseButton" runat="server" Text="Event ID - Get Data" onclick="Konferanse_Click" CausesValidation="false" />
<asp:RadioButtonList ID="chkHasCourseGroup" runat="server" AutoPostBack="true" OnSelectedIndexChanged="chkHasCourseGroup_SelectedIndexChanged" SelectedValue='<%# Eval("HasCourseGroup") %>'>
<asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
<asp:ListItem Text="No" Value="No"></asp:ListItem>
</asp:RadioButtonList>
CODE BEHIND:
protected void Konferanse_Click(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["DataConnString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
sqlString = "SELECT * from konferanse_Register where CourseID ='" + MyConferenceID.Text.Trim() + "'";
SqlCommand cmd = new SqlCommand(sqlString, con);
if (MyConferenceID.Text != "")
{
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
chkHasCourseGroup.SelectedValue = reader["HasCourseGroup"].ToString();
if (reader["HasCourseGroup"].ToString() == "Yes")
{
Gridview3.Visible = true;
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
DropDownList ddGroupType = (DropDownList)Gridview3.Rows[rowIndex].Cells[1].FindControl("dropDownGroupType");
TextBox tGroupName = (TextBox)Gridview3.Rows[rowIndex].Cells[2].FindControl("txtGroupName");
Gridview3.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
ddGroupType.SelectedValue = dt.Rows[i]["GroupType"].ToString();
tGroupName.Text = dt.Rows[i]["GroupName"].ToString();
rowIndex++;
}
}
Gridview3.DataSource = dt;
Gridview3.DataBind();
}
}
}
}
}
On Event button click, the Nested GridView is not displaying. How to solve this problem?
Many thanks in advance