<asp:datagrid id=DataGrid1 style="Z-INDEX: 104; LEFT: 304px; POSITION: absolute; TOP: 104px" runat="server" CssClass="grid" AutoGenerateColumns="False">
<Columns>

<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" />
<asp:BoundColumn DataField="Message Id" ReadOnly="False" HeaderText="Message Id" />
<asp:TemplateColumn HeaderText="Opcode">
<ItemTemplate>
<%#Container.DataItem("Opcode")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList AutoPostBack = false id="ddl_Opcode" runat="server" DataValueField="Opcode" DataTextField ="Opcode" DataSource ="<%#TempDataView%>" >

</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

<asp:BoundColumn DataField="Message Status" HeaderText="Message Status" ReadOnly="True" />
<asp:BoundColumn DataField="Error Descp" HeaderText="Error Descp" ReadOnly="True" />

</Columns>
</asp:datagrid>

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
populateDropDownList()
DataGrid1.EditItemIndex = e.Item.ItemIndex
End Sub


Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim myDDL As New DropDownList
myDDL = CType(e.Item.FindControl("ddl_Opcode"), DropDownList)
Response.Write(myDDL.SelectedItem.Value)
End Sub


Private Function populateDropDownList()
Dim mydatatable As New DataTable
mydatatable.Columns.Add("Opcode", Type.GetType("System.String"))
' Declare row
Dim myrow As DataRow
' create new row
myrow = mydatatable.NewRow
myrow("Opcode") = "CREATE"
mydatatable.Rows.Add(myrow)
myrow = mydatatable.NewRow
myrow("Opcode") = "UPDATE"
mydatatable.Rows.Add(myrow)
myrow = mydatatable.NewRow
myrow("Opcode") = "DELETE"
mydatatable.Rows.Add(myrow)
TempDataView = mydatatable.DefaultView


End Function


Here is the code...
It shows an error : Object refernce not set
The selected index value remains nothing...
Can u tell me where I have gone wrong?

hi,

you should assign autopostback=true

aspropDownList [B]AutoPostBack = true [/B]id="ddl_Opcode" runat="server" DataValueField="Opcode" DataTextField ="Opcode" DataSource ="<%#TempDataView%>" >

</aspropDownList>

and another thing you can directly assign mydatable.defualtview
instead of tempdatatable
Private Function populateDropDownList()
Dim mydatatable As New DataTable
mydatatable.Columns.Add("Opcode", Type.GetType("System.String"))
' Declare row
Dim myrow As DataRow
' create new row
myrow = mydatatable.NewRow
myrow("Opcode") = "CREATE"
mydatatable.Rows.Add(myrow)
myrow = mydatatable.NewRow
myrow("Opcode") = "UPDATE"
mydatatable.Rows.Add(myrow)
myrow = mydatatable.NewRow
myrow("Opcode") = "DELETE"
mydatatable.Rows.Add(myrow)
ddl_Opcode.Datasource = mydatatable.DefaultView
ddl_Opcode.Databind()


End Function
This article has been dead for over six months. Start a new discussion instead.