HighTechTalks DotNet Forums  

DropDownList Datagrid issues

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss DropDownList Datagrid issues in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default DropDownList Datagrid issues - 06-02-2006 , 01:28 PM






Hello everybody.

I have a DropDownList in my Datagrid.
The DropDownList is prepopulated with data.

I'm capturing the event OnItemDataBound, and as the rows are populated
I'm selecting the correct index in my DropDownList based on a value for
that row.

My issue is that it seems that instead of selecting the value in the
DropDownList for that row, it selects the value in all the
DropDownLists for that column in the entire DataGrid.

So all the rows have the same value selected in the DropDownList that
corresponds to the value of the item that was meant for the last row.

Anybody seen this before and can help me out?

Thanks in advanced.


Reply With Quote
  #2  
Old   
DomNewbie
 
Posts: n/a

Default Re: DropDownList Datagrid issues - 06-06-2006 , 10:20 AM






This is how I do it, though there may be a more elegant solution...

private void
DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//select the data from the datasource
DataRow[] drs =td.Stock.Select("rowGuide=" +
e.Item.Cells[2].Text);
//select the DropDownlist control you're looking at (Control 1 in cell
10)
DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
//set the dropdownlist to reflect the data
ddl.SelectedValue =drs[0]["InStock"].ToString();

}

msingh.russelmetals (AT) gmail (DOT) com wrote:

Quote:
Hello everybody.

I have a DropDownList in my Datagrid.
The DropDownList is prepopulated with data.

I'm capturing the event OnItemDataBound, and as the rows are populated
I'm selecting the correct index in my DropDownList based on a value for
that row.

My issue is that it seems that instead of selecting the value in the
DropDownList for that row, it selects the value in all the
DropDownLists for that column in the entire DataGrid.

So all the rows have the same value selected in the DropDownList that
corresponds to the value of the item that was meant for the last row.

Anybody seen this before and can help me out?

Thanks in advanced.


Reply With Quote
  #3  
Old   
DomNewbie
 
Posts: n/a

Default Re: DropDownList Datagrid issues - 06-06-2006 , 10:22 AM



This is how I do it, though there may be a more elegant solution...

private void
DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//select the data from the datasource
DataRow[] drs =td.Stock.Select("rowGuide=" +
e.Item.Cells[2].Text);
//select the DropDownlist control you're looking at (Control 1 in cell
10)
DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
//set the dropdownlist to reflect the data
ddl.SelectedValue =drs[0]["InStock"].ToString();

}

msingh.russelmetals (AT) gmail (DOT) com wrote:

Quote:
Hello everybody.

I have a DropDownList in my Datagrid.
The DropDownList is prepopulated with data.

I'm capturing the event OnItemDataBound, and as the rows are populated
I'm selecting the correct index in my DropDownList based on a value for
that row.

My issue is that it seems that instead of selecting the value in the
DropDownList for that row, it selects the value in all the
DropDownLists for that column in the entire DataGrid.

So all the rows have the same value selected in the DropDownList that
corresponds to the value of the item that was meant for the last row.

Anybody seen this before and can help me out?

Thanks in advanced.


Reply With Quote
  #4  
Old   
DomNewbie
 
Posts: n/a

Default Re: DropDownList Datagrid issues - 06-06-2006 , 10:24 AM



This is how I do it, though there may be a more elegant solution...

private void
DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//select the data from the datasource
DataRow[] drs =td.Stock.Select("rowGuide=" +
e.Item.Cells[2].Text);
//select the DropDownlist control you're looking at (Control 1 in cell
10)
DropDownList ddl=(DropDownList)e.Item.Cells[10].Controls[1];
//set the dropdownlist to reflect the data
ddl.SelectedValue =drs[0]["InStock"].ToString();

}

msingh.russelmetals (AT) gmail (DOT) com wrote:

Quote:
Hello everybody.

I have a DropDownList in my Datagrid.
The DropDownList is prepopulated with data.

I'm capturing the event OnItemDataBound, and as the rows are populated
I'm selecting the correct index in my DropDownList based on a value for
that row.

My issue is that it seems that instead of selecting the value in the
DropDownList for that row, it selects the value in all the
DropDownLists for that column in the entire DataGrid.

So all the rows have the same value selected in the DropDownList that
corresponds to the value of the item that was meant for the last row.

Anybody seen this before and can help me out?

Thanks in advanced.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.