User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 402,002 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,446 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 4044 | Replies: 4
Reply
Join Date: Dec 2006
Posts: 12
Reputation: Rocksoft is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rocksoft Rocksoft is offline Offline
Newbie Poster

please anybody to help Dropdownlist selected index problem

  #1  
Mar 7th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 58
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: please anybody to help Dropdownlist selected index problem

  #2  
Mar 8th, 2007
Are you calling FillDropDown() in the Page_Load event handler? if so does it look like this:

if(!IsPostBack)
{
    FillDropDown();
}
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Dec 2006
Posts: 12
Reputation: Rocksoft is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rocksoft Rocksoft is offline Offline
Newbie Poster

Re: please anybody to help Dropdownlist selected index problem

  #3  
Mar 8th, 2007
Originally Posted by hollystyles View Post
Are you calling FillDropDown() in the Page_Load event handler? if so does it look like this:

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.
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,165
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 58
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: please anybody to help Dropdownlist selected index problem

  #4  
Mar 8th, 2007
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 8:36 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Dec 2006
Posts: 12
Reputation: Rocksoft is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Rocksoft Rocksoft is offline Offline
Newbie Poster

Re: please anybody to help Dropdownlist selected index problem

  #5  
Mar 8th, 2007
Originally Posted by hollystyles View Post
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 9:10 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC