load a dropdownlist in VB when the edit is clicked in a datagrid P

G

Guest

I am trying to load a dropdownlist in VB when the edit is clicked in a
datagrid. How do i call Sub loaddd to load the dropdownlist

<asp:TemplateColumn runat="server" HeaderText="Id Type Option"
SortExpression="IdTypeOption">
<itemtemplate>
<asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem,
"TypeOption") %>' />
<asp:label runat="server" ID="LlbTypeOption" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>'/>
</itemtemplate>
<EditItemTemplate>
<asp:dropdownlist id="deViews" runat="server"></asp:dropdownlist>
<asp:label runat="server" ID="IdTypeOption" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>
</asp:TemplateColumn>


Sub loaddd(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles deViews.Load

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("Get_All_TypeofOptions", myConnection)

Dim dtrControlOption As New DataTable
Dim dropRowOption As DataRow

dtrControlOption.Columns.Add( _
New DataColumn("TypeOption", GetType(String)))

dtrControlOption.Columns.Add( _
New DataColumn("IdTypeOption", GetType(String)))

myConnection.Open()

Dim Optionfile As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)

While Optionfile.Read()
dropRowOption = dtrControlOption.NewRow()
dropRowOption("TypeOption") = Optionfile.Item("TypeOption")
dropRowOption("IdTypeOption") = Optionfile.Item("IdTypeOption")
dtrControlOption.Rows.Add(dropRowOption)

End While

deViews.DataSource = dtrControlOption
deViews.DataTextField = "TypeOption"
deViews.DataValueField = "IdTypeOption"
deViews.DataBind()

myConnection.Close()
Dim i As Integer
For i = 0 To deViews.Items.Count - 1
Dim opchk As String = deViews.Items(i).Value
Dim chk = deViews.DataValueField
If opchk = Session("typeofoption") Then
deViews.Items(i).Selected = True
End If
Next

End Sub
 
G

Guest

The following text is from MSDN documentation if you need further guidance
let me know.

Use the OnItemCommand method to provide a custom handler for the ItemCommand
event.

The ItemCommand event is raised when any button is clicked in the DataGrid
control. This event is commonly used to handle buttons controls with a custom
CommandName value, such as Add, in the DataGrid control.

Raising an event invokes the event handler through a delegate. For more
information, see Raising an Event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top