473,406 Members | 2,336 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,406 software developers and data experts.

How do you load a dropdownlist when edit is clicked in a datagrid

How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>
Jul 21 '05 #1
12 2746
Hi,
There are many ways to do it. One of them is to handle the ItemDataBound
event of the grid as given below:

if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList ddl = (DropDownList) e.Item.FindControl ("deViews");
// Build a dataset or data table with data to populate the drop-down
ddl.DataSource = <datatable name>;
ddl.DataTextField = <datatable col name>;
ddl.DataValueField = <datatable col name>;
ddl.DataBind();
}

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:8E**********************************@microsof t.com...
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>

Jul 21 '05 #2
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 to an instance of an object.

Here is the code:

<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" OnDataBinding="loaddd"
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 Object, ByVal e As System.EventArgs)

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()
BindOption()
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

"Shiva" wrote:
Hi,
There are many ways to do it. One of them is to handle the ItemDataBound
event of the grid as given below:

if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList ddl = (DropDownList) e.Item.FindControl ("deViews");
// Build a dataset or data table with data to populate the drop-down
ddl.DataSource = <datatable name>;
ddl.DataTextField = <datatable col name>;
ddl.DataValueField = <datatable col name>;
ddl.DataBind();
}

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:8E**********************************@microsof t.com...
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>

Jul 21 '05 #3
Try this one:

.... ...
<EditItemTemplate>
<asp:dropdownlist id="deViews" runat="server"></asp:dropdownlist>
.... ....
</EditItemTemplate>
.... ...

Assuming the datagrid id is dgrd1,

Sub dgrd1_ItemDataBound (sender As Object, e As DataGridItemEventArgs)
Handles dgrd1.ItemDataBound
If (e.Item.ItemType = ListItemType.EditItem) Then
DropDownList ddl = CType (e.Item.FindControl ("deViews"), DropDownList)

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

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

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

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:CF**********************************@microsof t.com...
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 to an instance of an object.

Here is the code:

<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" OnDataBinding="loaddd"
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 Object, ByVal e As System.EventArgs)

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()
BindOption()
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

"Shiva" wrote:
Hi,
There are many ways to do it. One of them is to handle the ItemDataBound
event of the grid as given below:

if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList ddl = (DropDownList) e.Item.FindControl ("deViews");
// Build a dataset or data table with data to populate the drop-down
ddl.DataSource = <datatable name>;
ddl.DataTextField = <datatable col name>;
ddl.DataValueField = <datatable col name>;
ddl.DataBind();
}

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:8E**********************************@microsof t.com...
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>

Jul 21 '05 #4
I still get this error. Object reference not set to an instance of an object.

Droplist deViews is it the EditItemTemplate
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 211: End While
Line 212:
Line 213: c.DataSource = dtrControlOption
Line 214: deViews.DataTextField = "TypeOption"
Line 215: deViews.DataValueField = "IdTypeOption"
Source File: C:\best\_OptionMaint.ascx.vb Line: 213


<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 Object, ByVal e As DataGridItemEventArgs)
Handles OptionGrid.ItemDataBound

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()
BindOption()
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
"Shiva" wrote:
Try this one:

.... ...
<EditItemTemplate>
<asp:dropdownlist id="deViews" runat="server"></asp:dropdownlist>
.... ....
</EditItemTemplate>
.... ...

Assuming the datagrid id is dgrd1,

Sub dgrd1_ItemDataBound (sender As Object, e As DataGridItemEventArgs)
Handles dgrd1.ItemDataBound
If (e.Item.ItemType = ListItemType.EditItem) Then
DropDownList ddl = CType (e.Item.FindControl ("deViews"), DropDownList)

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

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

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

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:CF**********************************@microsof t.com...
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 to an instance of an object.

Here is the code:

<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" OnDataBinding="loaddd"
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 Object, ByVal e As System.EventArgs)

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()
BindOption()
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

"Shiva" wrote:
Hi,
There are many ways to do it. One of them is to handle the ItemDataBound
event of the grid as given below:

if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList ddl = (DropDownList) e.Item.FindControl ("deViews");
// Build a dataset or data table with data to populate the drop-down
ddl.DataSource = <datatable name>;
ddl.DataTextField = <datatable col name>;
ddl.DataValueField = <datatable col name>;
ddl.DataBind();
}

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:8E**********************************@microsof t.com...
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>


Jul 21 '05 #5
Hi,

Your ItemDataBound code is still using the dropdown list id that was given
in the EditItemTemplate. However, this id cannot be used as is. You have to
find the dropdownlist control instance in the current daragrid row and use
that for further usage. If you look at the code in my reply, there is a line
like this:

DropDownList ddl = CType (e.Item.FindControl ("deViews"), DropDownList)

Use ddl wherever you are using deView.

Also, the whole dropdown list populating code should run only if the current
datagrid row is of EditItem type. So, you need this line as well:

If (e.Item.ItemType = ListItemType.EditItem) Then
'Populate the dropdown...
End If

HTH.

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:63**********************************@microsof t.com...
I still get this error. Object reference not set to an instance of an
object.

Droplist deViews is it the EditItemTemplate
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 211: End While
Line 212:
Line 213: c.DataSource = dtrControlOption
Line 214: deViews.DataTextField = "TypeOption"
Line 215: deViews.DataValueField = "IdTypeOption"
Source File: C:\best\_OptionMaint.ascx.vb Line: 213


<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 Object, ByVal e As DataGridItemEventArgs)
Handles OptionGrid.ItemDataBound

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()
BindOption()
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
"Shiva" wrote:
Try this one:

.... ...
<EditItemTemplate>
<asp:dropdownlist id="deViews" runat="server"></asp:dropdownlist>
.... ....
</EditItemTemplate>
.... ...

Assuming the datagrid id is dgrd1,

Sub dgrd1_ItemDataBound (sender As Object, e As DataGridItemEventArgs)
Handles dgrd1.ItemDataBound
If (e.Item.ItemType = ListItemType.EditItem) Then
DropDownList ddl = CType (e.Item.FindControl ("deViews"), DropDownList)
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

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

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

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:CF**********************************@microsof t.com...
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 to an instance of an object.

Here is the code:

<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" OnDataBinding="loaddd"
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 Object, ByVal e As System.EventArgs)

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()
BindOption()
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

"Shiva" wrote:
Hi,
There are many ways to do it. One of them is to handle the ItemDataBound
event of the grid as given below:

if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList ddl = (DropDownList) e.Item.FindControl ("deViews");
// Build a dataset or data table with data to populate the drop-down
ddl.DataSource = <datatable name>;
ddl.DataTextField = <datatable col name>;
ddl.DataValueField = <datatable col name>;
ddl.DataBind();
}

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:8E**********************************@microsof t.com...
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>


Jul 21 '05 #6
I can not get the drowdownlist loaded. How do i do that?

"Stanley J Mroczek" wrote:
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>

Jul 21 '05 #7
Hi,
Check these out. They have samples:
http://msdn.microsoft.com/library/de...tomcolumns.asp

http://www.4guysfromrolla.com/webtech/050801-1.shtml

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:7F**********************************@microsof t.com...
I can not get the drowdownlist loaded. How do i do that?

"Stanley J Mroczek" wrote:
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>

Jul 21 '05 #8

That works find!! THANK YOU

!! Now my problem is when the dropdownlist ddlMan.DataSource =
Yearfile.GetallManufacturer is changed

AutoPostBack=True OnSelectedIndexChanged= "newManufacturer"

How do get what was selected in (ddlMan)??

Sub newManufacturer(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtlbIIDManufacturer As Label
??????
End Sub
Private Sub loaddd(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles CarGrid.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then

Dim Yearfile As MaintenanceDB = New MaintenanceDB
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentYear As String = drv("IDCar")
Dim ddlyr As DropDownList = CType(e.Item.Cells(0).Controls(1),
DropDownList)
Dim ddlMan As DropDownList = CType(e.Item.Cells(1).Controls(1),
DropDownList)
Dim ddlModel As DropDownList =
CType(e.Item.Cells(2).Controls(1), DropDownList)

ddlyr.DataSource = Yearfile.GetAllYear
ddlyr.DataTextField = "YearDate"
ddlyr.DataValueField = "IDYear"
ddlyr.DataBind()

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

ddlMan.DataSource = Yearfile.GetallManufacturer
ddlMan.DataTextField = "Manufacturer"
ddlMan.DataValueField = "IDManufacturer"
ddlMan.DataBind()

For i = 0 To ddlMan.Items.Count - 1
Dim opchk As String = ddlMan.Items(i).Value
Dim chk = ddlMan.DataValueField
If opchk = Session("IdIDManufacturer") Then
ddlMan.Items(i).Selected = True
End If
Next


"Shiva" wrote:
Hi,
Check these out. They have samples:
http://msdn.microsoft.com/library/de...tomcolumns.asp

http://www.4guysfromrolla.com/webtech/050801-1.shtml

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:7F**********************************@microsof t.com...
I can not get the drowdownlist loaded. How do i do that?

"Stanley J Mroczek" wrote:
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>


Jul 21 '05 #9
This code gets the dropdownlist and from that you can get the selected
index. Have this in your newManufacturer() method:

Dim ddl As DropDownList
Dim item As DataGridItem = CarGrid.Items(CarGrid.EditItemIndex)
If (Not item Is Nothing) Then
ddl = CType (item.FindControl ("deViews"), DropDownList)
'Now, refer ddl.SelectedItem to get the selected item
End If

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:1C**********************************@microsof t.com...

That works find!! THANK YOU

!! Now my problem is when the dropdownlist ddlMan.DataSource =
Yearfile.GetallManufacturer is changed

AutoPostBack=True OnSelectedIndexChanged= "newManufacturer"

How do get what was selected in (ddlMan)??

Sub newManufacturer(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtlbIIDManufacturer As Label
??????
End Sub
Private Sub loaddd(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
CarGrid.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then

Dim Yearfile As MaintenanceDB = New MaintenanceDB
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentYear As String = drv("IDCar")
Dim ddlyr As DropDownList = CType(e.Item.Cells(0).Controls(1),
DropDownList)
Dim ddlMan As DropDownList = CType(e.Item.Cells(1).Controls(1),
DropDownList)
Dim ddlModel As DropDownList =
CType(e.Item.Cells(2).Controls(1), DropDownList)

ddlyr.DataSource = Yearfile.GetAllYear
ddlyr.DataTextField = "YearDate"
ddlyr.DataValueField = "IDYear"
ddlyr.DataBind()

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

ddlMan.DataSource = Yearfile.GetallManufacturer
ddlMan.DataTextField = "Manufacturer"
ddlMan.DataValueField = "IDManufacturer"
ddlMan.DataBind()

For i = 0 To ddlMan.Items.Count - 1
Dim opchk As String = ddlMan.Items(i).Value
Dim chk = ddlMan.DataValueField
If opchk = Session("IdIDManufacturer") Then
ddlMan.Items(i).Selected = True
End If
Next


"Shiva" wrote:
Hi,
Check these out. They have samples:
http://msdn.microsoft.com/library/de...tomcolumns.asp
http://www.4guysfromrolla.com/webtech/050801-1.shtml

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:7F**********************************@microsof t.com...
I can not get the drowdownlist loaded. How do i do that?

"Stanley J Mroczek" wrote:
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>


Jul 21 '05 #10
Thanks again thats it.

now that have the new select i want reload the ddlModel DropDownList

where do i call that?
Dim ddlModel As DropDownList = CType(e.Item.Cells(2).Controls(1),
DropDownList)

ddlModel.DataSource =
Yearfile.GetAllModelsbyManufacturer(Session("IdIDM anufacturer"))
ddlModel.DataTextField = "Models"
ddlModel.DataValueField = "IDModels"
ddlModel.DataBind()
"Shiva" wrote:
This code gets the dropdownlist and from that you can get the selected
index. Have this in your newManufacturer() method:

Dim ddl As DropDownList
Dim item As DataGridItem = CarGrid.Items(CarGrid.EditItemIndex)
If (Not item Is Nothing) Then
ddl = CType (item.FindControl ("deViews"), DropDownList)
'Now, refer ddl.SelectedItem to get the selected item
End If

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:1C**********************************@microsof t.com...

That works find!! THANK YOU

!! Now my problem is when the dropdownlist ddlMan.DataSource =
Yearfile.GetallManufacturer is changed

AutoPostBack=True OnSelectedIndexChanged= "newManufacturer"

How do get what was selected in (ddlMan)??

Sub newManufacturer(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtlbIIDManufacturer As Label
??????
End Sub
Private Sub loaddd(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
CarGrid.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then

Dim Yearfile As MaintenanceDB = New MaintenanceDB
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentYear As String = drv("IDCar")
Dim ddlyr As DropDownList = CType(e.Item.Cells(0).Controls(1),
DropDownList)
Dim ddlMan As DropDownList = CType(e.Item.Cells(1).Controls(1),
DropDownList)
Dim ddlModel As DropDownList =
CType(e.Item.Cells(2).Controls(1), DropDownList)

ddlyr.DataSource = Yearfile.GetAllYear
ddlyr.DataTextField = "YearDate"
ddlyr.DataValueField = "IDYear"
ddlyr.DataBind()

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

ddlMan.DataSource = Yearfile.GetallManufacturer
ddlMan.DataTextField = "Manufacturer"
ddlMan.DataValueField = "IDManufacturer"
ddlMan.DataBind()

For i = 0 To ddlMan.Items.Count - 1
Dim opchk As String = ddlMan.Items(i).Value
Dim chk = ddlMan.DataValueField
If opchk = Session("IdIDManufacturer") Then
ddlMan.Items(i).Selected = True
End If
Next


"Shiva" wrote:
Hi,
Check these out. They have samples:

http://msdn.microsoft.com/library/de...tomcolumns.asp

http://www.4guysfromrolla.com/webtech/050801-1.shtml

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:7F**********************************@microsof t.com...
I can not get the drowdownlist loaded. How do i do that?

"Stanley J Mroczek" wrote:
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>



Jul 21 '05 #11
Call it from the selectindexchanged event handler of the deViews
(newManufacturer?)

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:9A**********************************@microsof t.com...
Thanks again thats it.

now that have the new select i want reload the ddlModel DropDownList

where do i call that?
Dim ddlModel As DropDownList = CType(e.Item.Cells(2).Controls(1),
DropDownList)

ddlModel.DataSource =
Yearfile.GetAllModelsbyManufacturer(Session("IdIDM anufacturer"))
ddlModel.DataTextField = "Models"
ddlModel.DataValueField = "IDModels"
ddlModel.DataBind()
"Shiva" wrote:
This code gets the dropdownlist and from that you can get the selected
index. Have this in your newManufacturer() method:

Dim ddl As DropDownList
Dim item As DataGridItem = CarGrid.Items(CarGrid.EditItemIndex)
If (Not item Is Nothing) Then
ddl = CType (item.FindControl ("deViews"), DropDownList)
'Now, refer ddl.SelectedItem to get the selected item
End If

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:1C**********************************@microsof t.com...

That works find!! THANK YOU

!! Now my problem is when the dropdownlist ddlMan.DataSource =
Yearfile.GetallManufacturer is changed

AutoPostBack=True OnSelectedIndexChanged= "newManufacturer"

How do get what was selected in (ddlMan)??

Sub newManufacturer(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtlbIIDManufacturer As Label
??????
End Sub
Private Sub loaddd(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
CarGrid.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then

Dim Yearfile As MaintenanceDB = New MaintenanceDB
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentYear As String = drv("IDCar")
Dim ddlyr As DropDownList = CType(e.Item.Cells(0).Controls(1),
DropDownList)
Dim ddlMan As DropDownList = CType(e.Item.Cells(1).Controls(1), DropDownList)
Dim ddlModel As DropDownList =
CType(e.Item.Cells(2).Controls(1), DropDownList)

ddlyr.DataSource = Yearfile.GetAllYear
ddlyr.DataTextField = "YearDate"
ddlyr.DataValueField = "IDYear"
ddlyr.DataBind()

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

ddlMan.DataSource = Yearfile.GetallManufacturer
ddlMan.DataTextField = "Manufacturer"
ddlMan.DataValueField = "IDManufacturer"
ddlMan.DataBind()

For i = 0 To ddlMan.Items.Count - 1
Dim opchk As String = ddlMan.Items(i).Value
Dim chk = ddlMan.DataValueField
If opchk = Session("IdIDManufacturer") Then
ddlMan.Items(i).Selected = True
End If
Next


"Shiva" wrote:
Hi,
Check these out. They have samples:

http://msdn.microsoft.com/library/de...tomcolumns.asp

http://www.4guysfromrolla.com/webtech/050801-1.shtml

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:7F**********************************@microsof t.com...
I can not get the drowdownlist loaded. How do i do that?

"Stanley J Mroczek" wrote:
How do you load a dropdownlist when edit is clicked in a datagrid ?

<Columns>
<asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
HeaderText="Option Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<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" ?????="loaddd"
runat="server"></asp:dropdownlist>
<asp:label runat="server" Visible=False Text='<%#
DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
</EditItemTemplate>



Jul 21 '05 #12
i got it working here is the code THANK YOU FOR ALL YOUR HELP
STAN

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

Dim item As DataGridItem = CarGrid.Items(CarGrid.EditItemIndex)
If (Not item Is Nothing) Then
Dim Yearfile As MaintenanceDB = New MaintenanceDB
Dim ddl As DropDownList =
CType(item.FindControl("ManufacturerViews"), DropDownList)
'Now, refer ddl.SelectedItem to get the selected item
Session("IdIDManufacturer") = ddl.SelectedValue

Dim ddlModel As DropDownList =
CType(item.FindControl("ModelViews"), DropDownList)
ddlModel.DataSource =
Yearfile.GetAllModelsbyManufacturer(Session("IdIDM anufacturer"))
ddlModel.DataTextField = "Models"
ddlModel.DataValueField = "IDModels"
ddlModel.DataBind()

Dim ddlstyle As DropDownList =
CType(item.FindControl("StyleViews"), DropDownList)
ddlstyle.DataSource =
Yearfile.GetAllstylesbyManufacturer(Session("IdIDM anufacturer"),
Session("IdIDModels"))
ddlstyle.DataTextField = "Style"
ddlstyle.DataValueField = "IDStyles"
ddlstyle.DataBind()

End If

End Sub

"Shiva" wrote:
Call it from the selectindexchanged event handler of the deViews
(newManufacturer?)

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:9A**********************************@microsof t.com...
Thanks again thats it.

now that have the new select i want reload the ddlModel DropDownList

where do i call that?
Dim ddlModel As DropDownList = CType(e.Item.Cells(2).Controls(1),
DropDownList)

ddlModel.DataSource =
Yearfile.GetAllModelsbyManufacturer(Session("IdIDM anufacturer"))
ddlModel.DataTextField = "Models"
ddlModel.DataValueField = "IDModels"
ddlModel.DataBind()
"Shiva" wrote:
This code gets the dropdownlist and from that you can get the selected
index. Have this in your newManufacturer() method:

Dim ddl As DropDownList
Dim item As DataGridItem = CarGrid.Items(CarGrid.EditItemIndex)
If (Not item Is Nothing) Then
ddl = CType (item.FindControl ("deViews"), DropDownList)
'Now, refer ddl.SelectedItem to get the selected item
End If

HTH

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:1C**********************************@microsof t.com...

That works find!! THANK YOU

!! Now my problem is when the dropdownlist ddlMan.DataSource =
Yearfile.GetallManufacturer is changed

AutoPostBack=True OnSelectedIndexChanged= "newManufacturer"

How do get what was selected in (ddlMan)??

Sub newManufacturer(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txtlbIIDManufacturer As Label
??????
End Sub
Private Sub loaddd(ByVal sender As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
CarGrid.ItemDataBound

If e.Item.ItemType = ListItemType.EditItem Then

Dim Yearfile As MaintenanceDB = New MaintenanceDB
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim currentYear As String = drv("IDCar")
Dim ddlyr As DropDownList = CType(e.Item.Cells(0).Controls(1),
DropDownList)
Dim ddlMan As DropDownList =

CType(e.Item.Cells(1).Controls(1),
DropDownList)
Dim ddlModel As DropDownList =
CType(e.Item.Cells(2).Controls(1), DropDownList)

ddlyr.DataSource = Yearfile.GetAllYear
ddlyr.DataTextField = "YearDate"
ddlyr.DataValueField = "IDYear"
ddlyr.DataBind()

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

ddlMan.DataSource = Yearfile.GetallManufacturer
ddlMan.DataTextField = "Manufacturer"
ddlMan.DataValueField = "IDManufacturer"
ddlMan.DataBind()

For i = 0 To ddlMan.Items.Count - 1
Dim opchk As String = ddlMan.Items(i).Value
Dim chk = ddlMan.DataValueField
If opchk = Session("IdIDManufacturer") Then
ddlMan.Items(i).Selected = True
End If
Next


"Shiva" wrote:
Hi,
Check these out. They have samples:

http://msdn.microsoft.com/library/de...tomcolumns.asp

http://www.4guysfromrolla.com/webtech/050801-1.shtml

"Stanley J Mroczek" <St*************@discussions.microsoft.com> wrote in
message news:7F**********************************@microsof t.com...
I can not get the drowdownlist loaded. How do i do that?

"Stanley J Mroczek" wrote:

> How do you load a dropdownlist when edit is clicked in a datagrid ?
>
> <Columns>
> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True"
> HeaderText="Option Description"></asp:BoundColumn>
> <asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
> <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" ?????="loaddd"
> runat="server"></asp:dropdownlist>
> <asp:label runat="server" Visible=False Text='<%#
> DataBinder.Eval(Container.DataItem, "IdTypeOption") %>' />
> </EditItemTemplate>
>
>



Jul 21 '05 #13

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...
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: 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"...
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...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.