Need Help With Datagrid Template Column and Drop Down List Box

  • Thread starter Thread starter Benign Vanilla
  • Start date Start date
B

Benign Vanilla

I am a .NET newbie, and need some help.

I have a datagrid that is bound to a table. That works. I also have a
template column in the grid for updating a status value for each row. This
is defined as:

<asp:TemplateColumn HeaderText="New Order Status">
<ItemTemplate>
<asp:DropDownList Font-Names="Arial" Font-Size="XX-Small"
id="drpOrderStatus"
runat="server" AutoPostBack="true"
OnSelectedIndexChanged="drpOrderStatus_SelectedIndexChanged"
Width="165">
<asp:ListItem Value="0">New</asp:ListItem>
<asp:ListItem Value="1000">Loan Approved</asp:ListItem>
<asp:ListItem Value="1001">Loan Approved With
Gurantee</asp:ListItem>
<asp:ListItem Value="1002">Loan Declined</asp:ListItem>
<asp:ListItem Value="1003">Loan Requires More
Information</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>

In the click event of a button, Save button, I want to loop through my grid
and check the value of each drop box. I have not been able to get this to
work. In this event, I can put a watch on:

dgrdResults.items(i).cells(0).controls(1)

And I can see the drop down list box, but:

dgrdResults.items(i).cells(0).controls(1).SelectedValue

doesn't work. Any thoughts?

BV.
 
Hi Benign,

You need to convert the control to a dropdownlist. Try something like
the following.

DropDownList ddl =
(DropDownList)dgrdResults.items(i).cells(0).controls(1)
string myValue = ddl.SelectedValue
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com
 
Tod Birdsall said:
Hi Benign,

You need to convert the control to a dropdownlist. Try something like
the following.

DropDownList ddl =
(DropDownList)dgrdResults.items(i).cells(0).controls(1)
string myValue = ddl.SelectedValue
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com

Tod! Thanks! That was EXACTLY what I needed. Would you be able to point me
to some documentation that exlains the reason and purpose behind this? I'd
like to know what I just did.

BV.
 
Back
Top