Click here to Skip to main content
14,922,078 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<asp:GridView runat="server" ID="gridtest">
<columns> <asp:TemplateField>
<itemtemplate>
<asp:DropDownList ID="ddl_list" runat="server" AutoPostBack="true" EnableViewState="true"
OnSelectedIndexChanged="ddl_list_SelectedIndexChanged">
<asp:ListItem Text="1" Value="1">1
<asp:ListItem Text="2" Value="2">2
<asp:ListItem Text="3" Value="3">3





C#
protected void Page_Load(object sender, EventArgs e)
   {
       SqlConnection con = new SqlConnection();
       con.ConnectionString = ConfigurationManager.AppSettings[ConnectionString"];
       if (!Page.IsPostBack)
       {
           con.Open();
           SqlCommand cmd = new SqlCommand("Select * from Mas_exporter;, con);
           cmd.ExecuteNonQuery();
           SqlDataAdapter da = new SqlDataAdapter();
           da = new SqlDataAdapter(cmd);
           DataSet ds = new DataSet();
           da.Fill(ds);
           gridtest.DataSource = ds;
           gridtest.DataBind();
       }

   }
   protected void ddl_list_SelectedIndexChanged(object sender, EventArgs e)
   {
       Response.Write("Success");
   }


This one firing dropdown selectedindexchange Correctly. But in my case i can't bind gridview on PageLoad. i will bind gridview on button click event. If i bind Gridview on button Click event , Drop downlist selectedindexchange didn't firing...what i need to do?
Posted

1 solution

Could you please add ispostback function in page load


protected void Page_Load(object sender, EventArgs e)
{
if(!ispostback)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.AppSettings[ConnectionString"];
if (!Page.IsPostBack)
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Mas_exporter;, con);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gridtest.DataSource = ds;
gridtest.DataBind();
}
}

}
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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