Drop Down List Selected Value Problem
-
Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }
-
Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }
hi if u use following code in page_load then all code use within if(!Page.IsPostback) { ///statemane of ur programm here }
no knowledge in .net
-
hi if u use following code in page_load then all code use within if(!Page.IsPostback) { ///statemane of ur programm here }
no knowledge in .net
it is Listing all the values in the dropdownlist but when i select any value am not getting that value.getting selected value=null or selectedindex=-1
-
it is Listing all the values in the dropdownlist but when i select any value am not getting that value.getting selected value=null or selectedindex=-1
-
Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }
u can try this protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindYear(); } } private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataTextField = "dobYear"; cboYY.DataBind(); } YearTable.Dispose(); } protected void btn_Click(object sender, EventArgs e) { string a = Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; msg.Text = a + b; }
no knowledge in .net
-
Hi am binding the Data in the dropdownlist(cboYY).But after selecting the value am not getting the selected value always getting selectedIndex=-1 and the selected value is getting Null that code as follows string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue; Databinding code as follows private void bindYear() { DataTable YearTable = new DataTable(); DataColumn YearColumn; YearColumn = new DataColumn(); YearColumn.DataType = Type.GetType("System.String"); YearColumn.ColumnName = "dobYear"; YearTable.Columns.Add(YearColumn); YearTable.Rows.Add("YYYY"); for (int i = 1940; i <= DateTime.Now.Year; i++) { YearTable.Rows.Add(i); } if (YearTable.Rows.Count > 0) { cboYY.DataSource = YearTable; cboYY.DataBind(); } YearTable.Dispose(); }
Kurian_Kurian wrote:
string a =Convert.ToString(cboYY.SelectedIndex); string b = cboYY.SelectedValue;
I guess this you have written this in class and not in any methods. So this value will be set when the class instantiated. At that time dropdown selectedindex will be -1.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions