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

Setting the SelectedIndex of a DropDownList in a Datagrid

Hi There,

I have two datagrids on a webform both of which display DropDownLists when
edit mode is invoked.

That being said, does anyone have a generic or straightforward way in C# so
that when I go into the edit mode of a row, the dropdownlists display the
field values of that row? (They currently jump to the first value in the
dropdownlist)

Any help would be GREATLY appreciated,

_K.


Nov 18 '05 #1
4 3573
K Bryan wrote:
Hi There,

I have two datagrids on a webform both of which display DropDownLists when
edit mode is invoked.

That being said, does anyone have a generic or straightforward way in C# so
that when I go into the edit mode of a row, the dropdownlists display the
field values of that row? (They currently jump to the first value in the
dropdownlist)

Any help would be GREATLY appreciated,

_K.


grab the dropdown list from the datagrid

something like

for each item in DataGrid1.Items
dim ddl as DropDownList = item.FindControl("DropDownList1")
ddl.selectedItemIndex = MyIndexValue
next

remember to do it after databinding has been done, and not in Item_create

you can do it at Item_DataBound,
should work

hth
-ashish
Nov 18 '05 #2
You need to find the ddl in the collection of controls.
So you do something like this.
DropDownList ddl = (DropDownList) e.Item.FindControl("lstID");

then select the correct item as required

A
"K Bryan" <Ke***********@campi.org> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
Hi There,

I have two datagrids on a webform both of which display DropDownLists when
edit mode is invoked.

That being said, does anyone have a generic or straightforward way in C# so that when I go into the edit mode of a row, the dropdownlists display the
field values of that row? (They currently jump to the first value in the
dropdownlist)

Any help would be GREATLY appreciated,

_K.

Nov 18 '05 #3
Thanks for the reply.

Where would I put this code? What event?

"Andrew de la Harpe" <an*********@hotmail.com> wrote in message
news:u8****************@TK2MSFTNGP12.phx.gbl...
You need to find the ddl in the collection of controls.
So you do something like this.
DropDownList ddl = (DropDownList) e.Item.FindControl("lstID");

then select the correct item as required

A
"K Bryan" <Ke***********@campi.org> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
Hi There,

I have two datagrids on a webform both of which display DropDownLists when edit mode is invoked.

That being said, does anyone have a generic or straightforward way in C#

so
that when I go into the edit mode of a row, the dropdownlists display the field values of that row? (They currently jump to the first value in the
dropdownlist)

Any help would be GREATLY appreciated,

_K.


Nov 18 '05 #4
In the OnDataBound event for the grid.
Heres as example.
private void setDataBinding(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{
ListItemType lit = e.Item.ItemType;

if(lit == ListItemType.EditItem)

{

DataRowView drv = (DataRowView) e.Item.DataItem;

DropDownList dll = (DropDownList) e.Item.FindControl("lstLaterability");

etc..

}

}

"K Bryan" <Ke***********@campi.org> wrote in message
news:uH*************@TK2MSFTNGP12.phx.gbl...
Thanks for the reply.

Where would I put this code? What event?

"Andrew de la Harpe" <an*********@hotmail.com> wrote in message
news:u8****************@TK2MSFTNGP12.phx.gbl...
You need to find the ddl in the collection of controls.
So you do something like this.
DropDownList ddl = (DropDownList) e.Item.FindControl("lstID");

then select the correct item as required

A
"K Bryan" <Ke***********@campi.org> wrote in message
news:ex**************@TK2MSFTNGP11.phx.gbl...
Hi There,

I have two datagrids on a webform both of which display DropDownLists when edit mode is invoked.

That being said, does anyone have a generic or straightforward way in C#
so
that when I go into the edit mode of a row, the dropdownlists display the field values of that row? (They currently jump to the first value in

the dropdownlist)

Any help would be GREATLY appreciated,

_K.



Nov 18 '05 #5

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

Similar topics

2
by: Audrey | last post by:
Hi I have a DropDownList that is bind to my DataGrid's EditItemTemplate The datasource of my DDL is different from my datagrid's datasource Everytime the 'Edit' link is clicked, the default...
4
by: K Bryan | last post by:
Hi There, I have two datagrids on a webform both of which display DropDownLists when edit mode is invoked. That being said, does anyone have a generic or straightforward way in C# so that...
5
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all...
2
by: Kay Chan | last post by:
Hi All, I am going to using a editable datagrid, one of the field should be a dropdownlist, here is my code <EditItemTemplate> <asp:DropDownList ID="INVESTMENT_FUND_ID" DataSource="<%# ...
1
by: Tim::.. | last post by:
Can someone please tell me who I get the selectedindex of a dropdown in a datagrid??? I have the following code and it works but it doesn't select the correct value when I edit the dropdown...
2
by: jason | last post by:
Hello and Good Day. REALLY LOST. Running ASP.NET 1.1 Becuase I think I'm using my own controls smartnavigation does not appear to work for me. Stardard issue: I've got a datagrid thats...
1
by: Jason Wilson | last post by:
I have two dropdownlists that are bound to the same datasource and I have a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip...
1
by: pleaseexplaintome | last post by:
Hi all, I have a datagrid with a dropdownlist and would like to have the dropdownlist display a database value correctly while the grid is in edit mode. I have a templatecolumn as follows: ...
1
by: marcbb | last post by:
Hi all, I have a really strange problem working with Dropdownlists in a DataGrid. I'm trying to preselect some values from the DropDownlist for each row in the DataGrid, but it seems that...
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: 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...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...

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.