Help! Pulling my hair on this Datagrid problem!!!

  • Thread starter Thread starter SD
  • Start date Start date
S

SD

Hello,

I have a very simple datagrid and one of the columns is defined as a label
and on the edit template is a Dropdown ctrl.

<EditItemTemplate>
<asp:dropdownlist Width = "100%" runat="server" id="DropDown1"
OnSelectedIndexChanged ="DropDownList1_SelectedIndexChanged" AutoPostBack
=True DataSource='<%# ListofDesignations() %>' />
</EditItemTemplate>

All works well, the dropdown has all the values I need, my goal is to be
able to do something (look up part description) when the user selects a
value from the dropdown using the OnSelectedIndexChanged event which I
called DropDownList1_SelectedIndexChanged

Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs)

Dim strDDValue As String
strDDValue = DropDownList1.SelectedValue

End Sub

But it does not work! It does not recognize DropDownList1 it thinks it does
not exist! I've tried a bunch of things but I just can't seem to be able to
read the value that was selected on my datagrid while on edit mode through
the Dropdown control.

I'm using Visual Studio 2003 and this is an ASP.NET application. if you've
run into this problem please let me know how you fixed it.

Thank you!!!

SD
 
Hello SD,

You need to do the following. Set postback on the dropdonwlist to true
and then give it a commandName, such as 'change'. Then in your vb code,
create and event for the datagrid itemcommand e.g.
dg1_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dg1.ItemCommand

then in the code you do a select case for the command name e.g.

select case e.CommandName.ToString()
case "change"
'do stuff here
end select

put your code you want to do in the case.

another way is to use the already built in commands for the datagrid
such as the edit, update, cancel commands.

Do a search on google or on MSDN for the itemcommands on a datagrid,
there will be good examples for you.

Good luck
 
Back
Top