Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DropDownList Datagrid issues

Reply
Thread Tools

DropDownList Datagrid issues

 
 
msingh.russelmetals@gmail.com
Guest
Posts: n/a
 
      06-02-2006
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
 
 
 
 
DomNewbie
Guest
Posts: n/a
 
      06-06-2006
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();

}

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> 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
 
 
 
 
DomNewbie
Guest
Posts: n/a
 
      06-06-2006
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();

}

(E-Mail Removed) wrote:

> 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
 
DomNewbie
Guest
Posts: n/a
 
      06-06-2006
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();

}

(E-Mail Removed) wrote:

> 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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView: Filter DropDownList for another DropDownList =?Utf-8?B?SnVhbmpv?= ASP .Net 0 12-29-2005 07:44 AM
GridView: Filtr DropDownList from another DropDownList =?Utf-8?B?SnVhbmpv?= ASP .Net 0 12-23-2005 01:31 PM
databinding a Dropdownlist to another dropdownlist tshad ASP .Net 8 10-19-2005 10:00 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM



Advertisments