473,378 Members | 1,330 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,378 software developers and data experts.

DataGrid_Update Sees One DropDownList, Ignores Another

42
Assume a DataGrid that, during edit mode, has two DropDownMenus, ddlA
and ddlB. Upon clicking 'Save,' the app performs the simplified task
of copying the DDL values of each to a label.

Expand|Select|Wrap|Line Numbers
  1. public void dg_Update(Object sender, DataGridCommandEventArgs e)
  2. {
  3.         // VARIABLES --------------
  4.         DropDownList ddlA = (DropDownList) e.Item.FindControl("ddlAEdit");
  5.         DropDownList ddlB = (DropDownList) e.Item.FindControl("ddlBEdit");
  6.         // ------------------------
  7.  
  8.         Label1.Text = ddlA.SelectedValue + " " + ddlB.SelectedValue;
  9.  
  10. }
Expand|Select|Wrap|Line Numbers
  1. <columns>
  2.     <asp:templatecolumn>
  3.         <itemtemplate>blah</itemtemplate>
  4.         <edititemtemplate>
  5.             <asp:dropdownlist id="ddlAEdit" datasource="<%# FillAList() %>" datavaluefield="ID" datatextfield="Name" selectedvalue='<%# Convert.ToInt32(DataBinder.Eval(Container, "DataItem.AID")) %>' ondatabinding="ddlEdit_ItemDataBound" runat="server" />
  6.         </edititemtemplate>
  7.     </asp:templatecolumn>
  8.         <asp:templatecolumn>
  9.         <itemtemplate>blah</itemtemplate>
  10.         <edititemtemplate>
  11.             <asp:dropdownlist id="ddlBEdit" datasource="<%# FillBList() %>" selectedvalue='<%# DataBinder.Eval(Container, "DataItem.BID").ToString() %>' datavaluefield="ID" datatextfield="Name" ondatabinding="ddlEdit_ItemDataBound" runat="server" />
  12.         </edititemtemplate>
  13.     </asp:templatecolumn>
  14. </columns>
The output of Label1 will be 'X ', where X is the correct value from
ddlA -- ddlB's value is missing.

ddlB at least exists; were it not found, the app wouldn't operate at
all. Other quick checks confirm that the program recognises ddlB.
Despite this, it fails to see a SelectedItem there, while it reads the
same thing normally from its neighbour!

Thanks.
Jan 16 '08 #1
2 1173
nateraaaa
663 Expert 512MB
How are you setting the value and text for ddlB? Are you using DataBind()? When you debug your code what value is it giving you for ddlB.SelectedValue?

Nathan
Jan 16 '08 #2
spamguy
42
How are you setting the value and text for ddlB? Are you using DataBind()? When you debug your code what value is it giving you for ddlB.SelectedValue?

Nathan
ddlB is filled through FillBList(), which is more or less FillAList() adjusted for different data:

Expand|Select|Wrap|Line Numbers
  1. public DataSet FillBList()
  2. {
  3.     SqlConnection    fillConnection = new SqlConnection(connection_string);
  4.  
  5.     DataSet listDataSet = new DataSet();
  6.  
  7.     SqlDataAdapter listAdapter = new SqlDataAdapter("SELECT ID, Name FROM TableB UNION SELECT -1, '' ORDER BY Name", fillConnection);
  8.  
  9.     if (fillConnection.State != ConnectionState.Open)
  10.         fillConnection.Open();
  11.  
  12.     listAdapter.Fill(listDataSet, "TableB");
  13.     fillConnection.Close();
  14.  
  15.     return listDataSet;
  16. }
I use DataBind() in numerous places. The one that generates the DDLs upon clicking Edit is probably the one in the trigger dg_Edit(), which has nothing but setting the EditItemIndex and DataBind(). I am certain both DDLs are being data bound, because if I put something indicative in ddl_ItemDataBound() (e.g., disable the sending control to signify the function was triggered), both DDLs react.

ddlB.SelectedValue generates -1.
Jan 17 '08 #3

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

Similar topics

1
by: Marius | last post by:
Hi all, I need an asp:dropdownlist on a webform that is databound to a dataset. This works fine and returns the data to populate my dropdownlist. In the DB I only have valid data, but I need a...
0
by: william.oram | last post by:
Assume a DataGrid that, during edit mode, has two DropDownMenus, ddlA and ddlB. Upon clicking 'Save,' the app performs the simplified task of copying the DDL values of each to a label. public...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.