By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
12 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.