| | |
please anybody to help Dropdownlist selected index problem
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2006
Posts: 12
Reputation:
Solved Threads: 0
Hi
I am working in asp.net with C# web application, I have used visual studio 2003, i have used dropdownlist
in my application to populate the data from mysql database, i have got problem while i selected the item from
dropdownlist, its not selecting correct item i'm selecting from dropdownlist, i have 64 records in my table, but i
tried to work with upto 15 records it will not giving problem, when the scroll will enable to dropdownlist its
giving problem, its not selecting the correct record what i'm selecting in dropdownlist, i have used following
codes to fill dropdown and selected index,
public DataSet LoadShotTaskCode()
{
cmd = new MySqlCommand("HD_PROC_LOADSHOTTASK",global_con);
cmd.CommandType = CommandType.StoredProcedure;
adapter = new MySqlDataAdapter(cmd);
dataset = new DataSet();
adapter.Fill(dataset,"hd_tbl_taskcodes");
return dataset;
}
private void FillDropDown()
{
Access = new clshome();
ds = Access.LoadShotTaskCode();
if(ds.Tables[0].Rows.Count != 0 )
{
DropDownList1.DataTextField = "task_code";
DropDownList1.DataValueField = "task_description";
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
if(DropDownList1.Items.Count != 0)
{
TxtEditTaskCode.Text = ds.Tables[0].Rows[0]["task_code"].ToString();
TxtEditTaskDesc.Text = ds.Tables[0].Rows[0]["task_description"].ToString();
}
}
else
{
DropDownList1.Items.Clear();
}
}
public MySqlDataReader Select_ShotTaskCoes(string tcode)
{
MySqlCommand taskcmd = new MySqlCommand("select * from hd_tbl_taskcodes where task_code='"+ tcode+"'",global_con);
global_con.Open();
MySqlDataReader dr = taskcmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Access = new clshome();
MySqlDataReader taskdr = Access.Select_ShotTaskCoes(DropDownList1.SelectedItem.Text);
if(taskdr.Read())
{
TxtEditTaskCode.Text = taskdr.GetValue(0).ToString();
TxtEditTaskDesc.Text = taskdr.GetValue(1).ToString();
}
Access.global_con.Close();
}
please anybody help me to slove this problem, advanced Thanks for any reply.
Thanks.
I am working in asp.net with C# web application, I have used visual studio 2003, i have used dropdownlist
in my application to populate the data from mysql database, i have got problem while i selected the item from
dropdownlist, its not selecting correct item i'm selecting from dropdownlist, i have 64 records in my table, but i
tried to work with upto 15 records it will not giving problem, when the scroll will enable to dropdownlist its
giving problem, its not selecting the correct record what i'm selecting in dropdownlist, i have used following
codes to fill dropdown and selected index,
public DataSet LoadShotTaskCode()
{
cmd = new MySqlCommand("HD_PROC_LOADSHOTTASK",global_con);
cmd.CommandType = CommandType.StoredProcedure;
adapter = new MySqlDataAdapter(cmd);
dataset = new DataSet();
adapter.Fill(dataset,"hd_tbl_taskcodes");
return dataset;
}
private void FillDropDown()
{
Access = new clshome();
ds = Access.LoadShotTaskCode();
if(ds.Tables[0].Rows.Count != 0 )
{
DropDownList1.DataTextField = "task_code";
DropDownList1.DataValueField = "task_description";
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
if(DropDownList1.Items.Count != 0)
{
TxtEditTaskCode.Text = ds.Tables[0].Rows[0]["task_code"].ToString();
TxtEditTaskDesc.Text = ds.Tables[0].Rows[0]["task_description"].ToString();
}
}
else
{
DropDownList1.Items.Clear();
}
}
public MySqlDataReader Select_ShotTaskCoes(string tcode)
{
MySqlCommand taskcmd = new MySqlCommand("select * from hd_tbl_taskcodes where task_code='"+ tcode+"'",global_con);
global_con.Open();
MySqlDataReader dr = taskcmd.ExecuteReader(CommandBehavior.CloseConnection);
return dr;
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Access = new clshome();
MySqlDataReader taskdr = Access.Select_ShotTaskCoes(DropDownList1.SelectedItem.Text);
if(taskdr.Read())
{
TxtEditTaskCode.Text = taskdr.GetValue(0).ToString();
TxtEditTaskDesc.Text = taskdr.GetValue(1).ToString();
}
Access.global_con.Close();
}
please anybody help me to slove this problem, advanced Thanks for any reply.
Thanks.
Are you calling FillDropDown() in the Page_Load event handler? if so does it look like this:
ASP.NET Syntax (Toggle Plain Text)
if(!IsPostBack) { FillDropDown(); }
•
•
Join Date: Dec 2006
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
Are you calling FillDropDown() in the Page_Load event handler? if so does it look like this:
ASP.NET Syntax (Toggle Plain Text)
if(!IsPostBack) { FillDropDown(); }
Hi,
thanks for your immediate reply, i have called the fill dropdown method in page load but same problem continuing, could you please give some solution for this
Thanks.
ASP.NET Syntax (Toggle Plain Text)
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { TxtEditTaskCode.Text = DropDownList1.SelectedValue; TxtEditTaskDesc.Text = DropDownList1.SelectedItem.Text; }
1. Why hit database when you already have the data in the drop down.
2. DropDownList1.SelectedItem.Text is the 'Description' DropDownList1.SelectedValue is the 'Code'.
Last edited by hollystyles; Mar 8th, 2007 at 9:36 am.
•
•
Join Date: Dec 2006
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
ASP.NET Syntax (Toggle Plain Text)
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { TxtEditTaskCode.Text = DropDownList1.SelectedValue; TxtEditTaskDesc.Text = DropDownList1.SelectedItem.Text; }
1. Why hit database when you already have the data in the drop down.
2. DropDownList1.SelectedItem.Text is the 'Description' DropDownList1.SelectedValue is the 'Code'.
Hi,
Thanks lot, i did big mistake in table, i didnt set primary key for my tables, i have set the primary key for my table now, dropdownlist problem automically solved, thanks for your immediate reply, because your gave more boost and ideas to me.
Thanks.
![]() |
Similar Threads
- How to get a selected index from checklistbox (ASP.NET)
- Help with dropdownlist data adding? (VB.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: ASP.Net YAF Application Error
- Next Thread: Using Framesets
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net bc30451 beginner browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal formview gridview gudi iis javascript list listbox menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl textbox tracking treeview unauthorized validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






