473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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("C onnectionString"))
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.CloseConne ction)

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
Jul 21 '05 #1
1 1775
pm
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.

"Stanley J Mroczek" wrote:
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("C onnectionString"))
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.CloseConne ction)

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

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stanley J Mroczek | last post by:
How do load a dropdownlist when edit is clicked in a datagrid and mark the selected item true? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
12
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
3
by: Stanley J Mroczek | last post by:
I am trying to load a droplist in VB when the edit is clicked in a datagrid. I tried to use OnDataBinding and loading the droplist in subroutine "loaddd". I get this error Object reference not set...
1
by: George Durzi | last post by:
When my datagrid is in edit mode, one of my columns is edited using a drop down list. I'm able to bind the DropDownList to a DataSource when in edit mode. HOWEVER, I can't preset the...
1
by: Stanley J Mroczek | last post by:
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"...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.