I have gridview control on my form, in that grid i took one dropdownlist, whenever i select index above to 2, it is not selecting proper index.
code is bellow, please help ..
protected void grdMould_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlMouldNo = (e.Row.FindControl("ddlMouldNo") as DropDownList);
var soset = dc.SoilSetting_View("CBR Modi Mould Volume").ToList();
ddlMouldNo.DataSource = soset;
ddlMouldNo.DataTextField = "SOSET_F1_var";
ddlMouldNo.DataValueField = "F2plusF3";
ddlMouldNo.DataBind();
if (ddlMouldNo.Items.Count > 0)
ddlMouldNo.Items.Insert(0, new ListItem("Select", "0"));
}
}
protected void ddlMouldNo_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gvr = ((DropDownList)sender).NamingContainer as GridViewRow;
if (gvr != null)
{
TextBox txtVolume = (TextBox)gvr.FindControl("txtVolume");
TextBox txtHeight = (TextBox)gvr.FindControl("txtHeight");
DropDownList ddlMouldNo = (DropDownList)gvr.FindControl("ddlMouldNo");
if (ddlMouldNo.SelectedIndex > 0)
{
string[] arryValues= ddlMouldNo.SelectedItem.Value.Split('|');
txtVolume.Text = arryValues[0];
txtHeight.Text = arryValues[1];
}
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlMouldNo = (e.Row.FindControl("ddlMouldNo") as DropDownList);
var soset = dc.SoilSetting_View("CBR Modi Mould Volume").ToList();
ddlMouldNo.DataSource = soset;
ddlMouldNo.DataTextField = "SOSET_F1_var";
ddlMouldNo.DataValueField = "F2plusF3";
ddlMouldNo.DataBind();
if (ddlMouldNo.Items.Count > 0)
ddlMouldNo.Items.Insert(0, new ListItem("Select", "0"));
}
}
protected void ddlMouldNo_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow gvr = ((DropDownList)sender).NamingContainer as GridViewRow;
if (gvr != null)
{
TextBox txtVolume = (TextBox)gvr.FindControl("txtVolume");
TextBox txtHeight = (TextBox)gvr.FindControl("txtHeight");
DropDownList ddlMouldNo = (DropDownList)gvr.FindControl("ddlMouldNo");
if (ddlMouldNo.SelectedIndex > 0)
{
string[] arryValues= ddlMouldNo.SelectedItem.Value.Split('|');
txtVolume.Text = arryValues[0];
txtHeight.Text = arryValues[1];
}
}
}
Khargesh RajputPosted Mar 24, 2015, 6:03 AM
how many items in dropdownlist
do you want ddlMouldNo.selectedvalue or
ddlMouldNo .selectitem