This is function that I used to load combobox. I can load combobox but when I try to get selectedvalue
of combobox it showing null
; I am not getting the actual value.
public static DataTable GetComboBoxedDataTable(DataTable oldDataTable, string valueColumn, string textColumn, string topRowValue, string topRowText, ComboBox cmb) { DataTable newDataTable = new DataTable(); newDataTable.Columns.Add(valueColumn); newDataTable.Columns.Add(textColumn); foreach (DataRow oldDR in oldDataTable.Rows) { DataRow newDR = newDataTable.NewRow(); newDR[0] = oldDR[valueColumn].ToString(); newDR[1] = oldDR[textColumn].ToString(); newDataTable.Rows.InsertAt(newDR, newDataTable.Rows.Count); } // Add your 'Select an item' option at the top DataRow dr = newDataTable.NewRow(); dr[0] = topRowValue; dr[1] = topRowText; newDataTable.Rows.InsertAt(dr, 0); cmb.ValueMember = valueColumn; cmb.DisplayMember = textColumn; return newDataTable; }
the code where i am in need of combobox.selectedvalue
private void cmbroomno_SelectedIndexChanged(object sender, EventArgs e) { try { object[,] ParamArray = new object[,] { { "@RoomID", cmbroomno.SelectedValue } };---code where i need selected value DataSet ds = new DataSet(); ds = DB.ExecuteQuery_SP("SelectGuestDetailsForService", ParamArray);