Home All Groups Group Topic Archive Search About
Author
13 Jun 2005 4:26 PM
dl
Hi
I have a datagrid defined which I would like to make it editable. So I put
in some editcommand and BoundColumn and template column with item template.
I don't have problem in setting a column to textbox in edititemtemplate, but
how do I set it to dropdownlist and how do I set the selectedIndex?

TIA

--

Author
13 Jun 2005 4:44 PM
Brock Allen
You can handle the DataGrid's ItemDataBound event. The DataGridItemEventArgs
passed allows you to access the e.Item which is the row in the DataGrid.
Find the cell you want, then use FindControl("IDOfYourDDL") to get your DropDownList
in the Cell. Once you have that, you can do any custom work with it you need
to.

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> Hi
> I have a datagrid defined which I would like to make it editable. So I
> put
> in some editcommand and BoundColumn and template column with item
> template.
> I don't have problem in setting a column to textbox in
> edititemtemplate, but
> how do I set it to dropdownlist and how do I set the selectedIndex?
> TIA
>
Author
13 Jun 2005 5:06 PM
dl
Do you mean I should use ItemDataBound event to bind data to the
dropdownlist control and disable it before the DataGrid got displayed, then
onEditCommand event, I simply enable the control?

TIA

Show quoteHide quote
"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
news:889665632542634599814224@msnews.microsoft.com...
> You can handle the DataGrid's ItemDataBound event. The
DataGridItemEventArgs
> passed allows you to access the e.Item which is the row in the DataGrid.
> Find the cell you want, then use FindControl("IDOfYourDDL") to get your
DropDownList
> in the Cell. Once you have that, you can do any custom work with it you
need
> to.
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > Hi
> > I have a datagrid defined which I would like to make it editable. So I
> > put
> > in some editcommand and BoundColumn and template column with item
> > template.
> > I don't have problem in setting a column to textbox in
> > edititemtemplate, but
> > how do I set it to dropdownlist and how do I set the selectedIndex?
> > TIA
> >
>
>
>
Author
13 Jun 2005 6:40 PM
Brock Allen
To change the Selected item in the DDL, you're going to have to get access
to the DDL. This can be accomplished by handling the ItemDataBound event
on the Grid. Oh, one other thing I should have mentioned is that since you're
only doing this when you edit the row, you should double check for e.Item.ItemType
== ListItemType.EditItem.

Oh, just rereading your original post, I think what you're going to want
is to put a EditItemTemplate. Inside of that put your own DDL. And then,
yes, in the ItemDataBound you can data bind the DDL to whatever list it needs
to be.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Show quoteHide quote
> Do you mean I should use ItemDataBound event to bind data to the
> dropdownlist control and disable it before the DataGrid got displayed,
> then onEditCommand event, I simply enable the control?
>
> TIA
>
> "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
> news:889665632542634599814224@msnews.microsoft.com...
>
>> You can handle the DataGrid's ItemDataBound event. The
>>
> DataGridItemEventArgs
>
>> passed allows you to access the e.Item which is the row in the
>> DataGrid. Find the cell you want, then use FindControl("IDOfYourDDL")
>> to get your
>>
> DropDownList
>
>> in the Cell. Once you have that, you can do any custom work with it
>> you
>>
> need
>
>> to.
>>
>> -Brock
>> DevelopMentor
>> http://staff.develop.com/ballen
>>> Hi
>>> I have a datagrid defined which I would like to make it editable. So
>>> I
>>> put
>>> in some editcommand and BoundColumn and template column with item
>>> template.
>>> I don't have problem in setting a column to textbox in
>>> edititemtemplate, but
>>> how do I set it to dropdownlist and how do I set the selectedIndex?
>>> TIA
Author
13 Jul 2005 9:23 PM
Eric
Hi, Brock.

I've spent the past 5 hours on this problem, trying to figure out how to
change the SelectedValue, something that should really only take 30 second. 
I've stumped three other developers in my small office.

With your help I still can't quite get it.

I have a static list for the DDL but I need to change the SelectedValue to
the data that's being edited in the template column of the DataList.  I'm not
inputting the list from a DataReader or anything.

The problem is I can't access or find the DDL control.  I've got a hunch
that the control I want might not exist when I am trying to access it, since
it's built on-the-fly (template).

I've got a dl_EditCommand sub and a dl_ItemDataBound (I just added this one
as per your suggestion).  When I click "Edit", ItemDataBound fires before the
EditCommand is fired.  Is there a method that fires later than these two?

Help is much appreciated!
--
Eric

Show quoteHide quote
"Brock Allen" wrote:

> To change the Selected item in the DDL, you're going to have to get access
> to the DDL. This can be accomplished by handling the ItemDataBound event
> on the Grid. Oh, one other thing I should have mentioned is that since you're
> only doing this when you edit the row, you should double check for e.Item.ItemType
> == ListItemType.EditItem.
>
> Oh, just rereading your original post, I think what you're going to want
> is to put a EditItemTemplate. Inside of that put your own DDL. And then,
> yes, in the ItemDataBound you can data bind the DDL to whatever list it needs
> to be.
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
> > Do you mean I should use ItemDataBound event to bind data to the
> > dropdownlist control and disable it before the DataGrid got displayed,
> > then onEditCommand event, I simply enable the control?
> >
> > TIA
> >
> > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
> > news:889665632542634599814224@msnews.microsoft.com...
> >
> >> You can handle the DataGrid's ItemDataBound event. The
> >>
> > DataGridItemEventArgs
> >
> >> passed allows you to access the e.Item which is the row in the
> >> DataGrid. Find the cell you want, then use FindControl("IDOfYourDDL")
> >> to get your
> >>
> > DropDownList
> >
> >> in the Cell. Once you have that, you can do any custom work with it
> >> you
> >>
> > need
> >
> >> to.
> >>
> >> -Brock
> >> DevelopMentor
> >> http://staff.develop.com/ballen
> >>> Hi
> >>> I have a datagrid defined which I would like to make it editable. So
> >>> I
> >>> put
> >>> in some editcommand and BoundColumn and template column with item
> >>> template.
> >>> I don't have problem in setting a column to textbox in
> >>> edititemtemplate, but
> >>> how do I set it to dropdownlist and how do I set the selectedIndex?
> >>> TIA
>
>
>
>