473,494 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I get a label's value in a datagrid for a dropdownlist?

I have a dropdownlist that I want to default to the proper value in the
list. It should be what the current value of the label is before I
press edit.

Any ideas?

Nov 19 '05 #1
1 1197
if(e.Item.ItemType == ListItemType.EditItem)
{
//how to find the current value that is in the database and use that
//as the way to preselect the appropriate item from the dropdownlist
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl. asp

DataRowView drvCity = (DataRowView) e.Item.DataItem;
String CurrentCity = drvCity["city_code"].ToString(); //city_code is
the database column
DropDownList ddlCity = (DropDownList)
e.Item.FindControl("ddl_edit_cities");
ddlCity.SelectedIndex =
ddlCity.Items.IndexOf(ddlCity.Items.FindByText(Cur rentCity));

DataRowView drvEdit = (DataRowView) e.Item.DataItem;
String CurrentIndicator = drvEdit["indicator"].ToString();
DropDownList ddlEdit = (DropDownList)
e.Item.FindControl("ddl_edit_indicator");
ddlEdit.SelectedIndex =
ddlEdit.Items.IndexOf(ddlEdit.Items.FindByValue(Cu rrentIndicator));
//notice this last one is FindByValue because the values in the
listitems
//are different than than the text displayed to the user

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1792
by: DC Gringo | last post by:
I've got a command button to submit a value from a dropdown list that should then filter a SELECT query. I'm simply appending a WHERE colx = <variableSelectedFromDropdownList>. How do I pass this...
6
5383
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
0
962
by: needin4mation | last post by:
Hi, consider this snippet, please: private void dgdHistory_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { string city=null; if...
2
2112
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the...
0
1833
by: rmccinc | last post by:
I have a dropdownlist in a datagrid and it has autopostback set to true. I need to get the new value of that dropdown to fill a textbox in the same datagrid row. I have set the databind event on...
0
1166
by: Vagabond Software | last post by:
I am fairly new to ASP.NET, so bear with me... I have a Datagrid with a data-bound DropDownList in the TemplateColumn. Here is the HTML code: <asp:TemplateColumn HeaderText="Void"> <ItemStyle...
2
3844
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub ShowData(obj As Object, ea As EventArgs) lblDate.Text = DateTime.Now.ToString("d") lblDate.DataBind() End Sub </script> <form...
1
2604
by: staeri | last post by:
I have a datagrid containing one TemplateColumn with a label (lblObjectID) and one TemplateColumn with a DropDownList. When the DropDownList is changed I want to capture the value in the...
2
1860
by: Igor | last post by:
Hi I build a page that has a dropdownlist control bound with data from a database. When user select an item from the dropdownlist I want a label to be filled with a result from a stored...
0
7119
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
7157
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,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.