473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with second dropdownlist in DataList

1
Hello everyone,

I have a datalist where i have two dropdowns the first to select a table and the second to select the column. So far so go...the problem starts when I go for the next item in the datalist and make a selection on the Dropdownlist "ddlTable". After doing this the second dropdownlist of the previous changes its value to the first possible item. Can you help me out?!

Here is the code:

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
  6.                 if (!scriptManager.IsInAsyncPostBack && !IsPostBack)
  7.                 {
  8.                     DataList_Load(DataListItems);
  9.                 }
  10.             }
  11.             catch (Exception ex)
  12.             {
  13.                 throw ex;
  14.             }
  15.         }
  16.  
  17.         protected void DataList_Load(int itens)
  18.         {
  19.             try
  20.             {
  21.                 List<int> myList = new List<int>();
  22.                 for (int i = 0; i < itens; i++)
  23.                     myList.Add(i);
  24.  
  25.                 dlQuery.DataSource = myList;
  26.                 dlQuery.DataBind();
  27.  
  28.             }
  29.             catch (Exception ex)
  30.             {
  31.                 throw ex;
  32.             }
  33.         }
  34.  
  35.         protected void dlQuery_ItemDataBound(object sender, DataListItemEventArgs e)
  36.         {
  37.             try
  38.             {
  39.                 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  40.                 {
  41.                     var ddl = e.Item.FindControl("ddlTable") as DropDownList;
  42.                     ddlTable_Load(ddl);
  43.                 }
  44.             }
  45.             catch (Exception ex)
  46.             {
  47.                 throw ex;
  48.             }
  49.         }
  50.  
  51.         protected void ddlTable_Load(DropDownList ddl)
  52.         {
  53.             try
  54.             {
  55.                 Connection cn = new Connection();
  56.                 SqlConnection SQLConn = cn.SqlLocalConn;
  57.                 SqlCommand SQLcmd = new SqlCommand("stp_Portal_GlobalMgmtQueryItens", SQLConn);
  58.                 SQLcmd.CommandType = System.Data.CommandType.StoredProcedure;
  59.  
  60.                 ddl.DataSource = cn.ExecuteSqlCmd(SQLConn, SQLcmd);
  61.                 ddl.DataTextField = "name";
  62.                 ddl.DataValueField = "id";
  63.                 ddl.DataBind();
  64.  
  65.                 ddl.Items.Insert(0, "Select one");
  66.             }
  67.             catch (Exception ex)
  68.             {
  69.                 throw ex;
  70.             }
  71.         }
  72.  
  73.         protected void ddlTable_SelectedIndexChanged(object sender, EventArgs e)
  74.         {
  75.             try
  76.             {
  77.                 DropDownList ddl1 = sender as DropDownList;
  78.                 if (ddl1.SelectedIndex > 0)
  79.                 {
  80.                     //string aux = ddl1.UniqueID;
  81.                     DropDownList ddl2 = (DropDownList)ddl1.Parent.FindControl("ddlColumn");
  82.                     //string aux2 = ddl2.UniqueID;
  83.                     ddlColumn_Load(ddl2, ddl1.SelectedValue);
  84.                 }
  85.             }
  86.             catch (Exception ex)
  87.             {
  88.                 throw ex;
  89.             }
  90.         }
  91.  
  92.         protected void ddlColumn_Load(DropDownList ddl, string val)
  93.         {
  94.             try
  95.             {
  96.                 Connection cn = new Connection();
  97.                 SqlConnection SQLConn = cn.SqlLocalConn;
  98.                 SqlCommand SQLcmd = new SqlCommand("stp_Portal_GlobalMgmtQueryItemColumns", SQLConn);
  99.                 SQLcmd.CommandType = System.Data.CommandType.StoredProcedure;
  100.                 SQLcmd.Parameters.Add("@intTableId", SqlDbType.Int).Value = val;
  101.  
  102.                 ddl.DataSource = cn.ExecuteSqlCmd(SQLConn, SQLcmd);
  103.                 ddl.DataTextField = "name";
  104.                 ddl.DataValueField = "id";
  105.                 ddl.DataBind();
  106.  
  107.                 ddl.Items.Insert(0, "Select one");
  108.             }
  109.             catch (Exception ex)
  110.             {
  111.                 throw ex;
  112.             }
  113.         }
  114.  
  115.         protected void ddlColumn_SelectedIndexChanged(object sender, EventArgs e)
  116.         {
  117.             try
  118.             {
  119.                 DropDownList ddl = sender as DropDownList;
  120.                 if (ddl.SelectedIndex > 0)
  121.                 {
  122.                     //just for test
  123.                 }
  124.             }
  125.             catch (Exception ex)
  126.             {
  127.                 throw ex;
  128.             }
  129.         }
Sep 24 '13 #1
0 1063

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jenny C. | last post by:
Hi Guys I have this problem: I'm trying to put a LinkButton inside a Datalist. But I can't add an event handle for the button. If I double click on the LinkButton, I get forwarded to the method :...
5
by: Bob N | last post by:
I have an ASP.NET web page -- several auto-post back DropDownLists that perform a query against a relatively large database (3 to 4 seconds delay) that repopulate a couple of datagrids, comboboxes...
4
by: Keith | last post by:
I have this simple scenario. -------- Choose an item ->dropdownlist-> or <a>Create a new item</a> -------- When someone decides to click on the create a new item link, it takes them to a...
2
by: Przemo | last post by:
Hi, I have a DropDownList, which is based on a DataTable generated from SQLServer. It consists of two fields: ID and Name. ID starts from "1" I Would like to add a special row to my...
2
by: Vadivel Kumar | last post by:
I have one datalist which contains one item template. In that, iam printing a value taken from the sql table and one check box. Now, the user will select some checkbox and press a button and that...
1
by: Swandi Candra | last post by:
Hi all, Did anyone experience a problem using DROPDOWNLIST control in ASP.NET? <ASP:DROPDOWNLIST ID="lstStaffs" RUNAT="SERVER"/> I got a runtime error whenever I used it in my script. ...
2
by: PW | last post by:
I'm seeing the (now famous) error when adding the second dropdownlist to the formview. Thank you Mr. Phillip Williams for posting a workaround to this error on your web site at:...
2
by: scottls | last post by:
Hi All, Thanks for reading my post. I have been working on getting nested datalists working properly wihtin my framework for many days and I think I'm almost there. See if you could help me...
0
coolv
by: coolv | last post by:
Hello Everyone I want to Reload Second Dropdownlist from selected value of first Dropdownlist using Ajax in ASp.NET Also I want a to make validation using Ajax on page. Can anyone help me. ...
6
by: looserash | last post by:
HI, I have a problem with dropdownlist.i have populated dropdownlist.my problem is i have to place a particular item in ddl which is already stored in sql 2000 database.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.