Sir,
I have in the problem of cannot write GridView DropdownList SelectIndexChanged Event in ASP.NET.
I cannot click on the DropdownList Control and to invoke SelectIndex Changed Event. get selected the GridView wholly.
I cannot access a individual control inside the gridview. Please help me on this difficulty
GridView looks like this:-
and the html code is:-
HTML CODE START
onrowdatabound="GridView1_RowDataBound" ForeColor="#333333"
>
<%#Container.DataItemIndex+1 %>
HTML CODE END

Usha RajPosted Apr 7, 2015, 7:31 AM
like this you should write for each dropdown then only you get the selection id of particular item name
Bineesh ViswanathPosted Apr 7, 2015, 7:16 AM
The html code to define the DropdownList is:-
The html code highlighted is the code for the DropDownList.
I write a code for SelectedIndexChanged Event like this : OnselectIndexChanged="ddlProductSelectIndexChanged" and wrote a event to handle this, but in vain, not firing the event:-
protected void ddlProduct_SelectIndexChanged(object sender, GridViewRowEventArgs e)
{
try
{
string strCon = ConfigurationManager.ConnectionStrings["ORDERS"].ToString();
SqlConnection sqlCon = new SqlConnection(strCon);
sqlCon.Open();
DropDownList ddlProduct = (DropDownList)GridView1.Rows[0].FindControl("ddlProduct");
SqlCommand cmd = new SqlCommand("getProductRateforCombo", sqlCon);
cmd.Parameters.Add("@as_itemValue", SqlDbType.Decimal).Value = ddlProduct.SelectedValue;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
adapter.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
TextBox txtRate = (TextBox)GridView1.Rows[0].FindControl("txtRate");
txtRate.Text = ds.Tables[0].Rows[0]["Mrp"].ToString();
}
}
catch (Exception ex)
{
throw;
}
}
Deepak SainiPosted Apr 7, 2015, 6:56 AM
If make the event on the control u can easily access easily control event. where r u put the control u make a event on that and put your code.i hope its work fine.