Я связываю выпадающий список в GridView на gv_RowDataBound
.В течение gv_onSelectionIndexChanged
,
выбранный индекс всегда равен 2, что является третьим значением в раскрывающемся списке, несмотря на выбор любого другого значения.
Я пытался получить значение индекса, выбранного значения или выбранного элемента, это всегда индекс 2.
Изображение Gridview 1
GridviewИзображение 2
Код для onRowDataBound
Код, где я пытаюсь получить выбранное DropDownList значение или индекс или что-либо еще
'Font-Size = "Small" Width = "40px">' Font-Size = "Small" Width = "40px"> 'Font-Size = "Small" Width = "210px">' Font-Size = "Small "Width =" 50px "> 'Font-Size =" Small "Width =" 40px "ReadOnly =" true "BackColor =" # CCCCCC ">
защищенная пустотаgvBillOfLadings_RowDataBound (отправитель объекта, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlBLDescription");
//ddl.DataSource = your_data_source_here;
//ddl.DataBind();
// Populate Bill Of Ladings Choose Description dropdownlist
String customerIDSession = Session["CustomerID"] != null ? Session["CustomerID"].ToString() : null;
String connStrLogo = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connStrLogo);
string getBLDescriptions = "SELECT Description, Class FROM COMMODITY WHERE customerID = '" + customerIDSession + "' ORDER BY Description";
conn.Open();
DataTable dt_BLDescriptions = new DataTable();
SqlDataAdapter adpatpter_BLDescriptions = new SqlDataAdapter(getBLDescriptions, conn);
adpatpter_BLDescriptions.Fill(dt_BLDescriptions);
ddl.DataSource = dt_BLDescriptions;
ddl.DataTextField = "Description";
ddl.DataValueField = "Class";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("CHOOSE DESCRIPTION", "0"));
conn.Close();
// End of populating Bill of Lading Items Gridview Description
}
}
protected void ddlBLDescription_SelectedIndexChanged (отправитель объекта, EventArgs e) {
GridViewRow gvr = (GridViewRow)(((Control)sender).NamingContainer);
DropDownList duty = (DropDownList)gvr.FindControl("ddlBLDescription");
String Text = duty.SelectedItem.ToString();
DropDownList ddl = (DropDownList)sender;
Session["slectedValue"] = ddl.SelectedIndex;
//GridViewRow row = (GridViewRow)ddl.NamingContainer;
GridViewRow row = (GridViewRow)ddl.NamingContainer;
String zero = ddl.Items[0].Text;
String one = ddl.Items[1].Text;
String two = ddl.Items[2].Text;
String three = ddl.Items[3].Text;
DropDownList list = (DropDownList)row.FindControl("ddlBLDescription");
String val = list.SelectedValue;
String item = list.SelectedItem.ToString();
TextBox txtDesc = (TextBox)row.FindControl("Description");
txtDesc.Text = ddl.SelectedItem.Text;
TextBox txtClass = (TextBox)row.FindControl("Class");
txtClass.Text = ddl.SelectedValue;
}