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:TemplateCo lumn runat="server" HeaderText="Id Type Option"
SortExpression= "IdTypeOpti on">
<itemtemplate >
<asp:label runat="server" Text='<%# DataBinder.Eval (Container.Data Item,
"TypeOption ") %>' />
<asp:label runat="server" ID="LlbTypeOpti on" Visible=False Text='<%#
DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>'/>
</itemtemplate>
<EditItemTempla te>
<asp:dropdownli st id="deViews" OnDataBinding=" loaddd"
runat="server"> </asp:dropdownlis t>
<asp:label runat="server" ID="IdTypeOptio n" Visible=False Text='<%#
DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>' />
</EditItemTemplat e>
</asp:TemplateCol umn>
Sub loaddd(ByVal sender As Object, ByVal e As System.EventArg s)
Dim myConnection As SqlConnection = New
SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
Dim myCommand As SqlCommand = New
SqlCommand("Get _All_TypeofOpti ons", myConnection)
Dim dtrControlOptio n As New DataTable
Dim dropRowOption As DataRow
dtrControlOptio n.Columns.Add( _
New DataColumn("Typ eOption", GetType(String) ))
dtrControlOptio n.Columns.Add( _
New DataColumn("IdT ypeOption", GetType(String) ))
myConnection.Op en()
Dim Optionfile As SqlDataReader =
myCommand.Execu teReader(Comman dBehavior.Close Connection)
While Optionfile.Read ()
dropRowOption = dtrControlOptio n.NewRow()
dropRowOption(" TypeOption") = Optionfile.Item ("TypeOption ")
dropRowOption(" IdTypeOption") = Optionfile.Item ("IdTypeOption" )
dtrControlOptio n.Rows.Add(drop RowOption)
End While
deViews.DataSou rce = dtrControlOptio n
deViews.DataTex tField = "TypeOption "
deViews.DataVal ueField = "IdTypeOpti on"
deViews.DataBin d()
myConnection.Cl ose()
BindOption()
Dim i As Integer
For i = 0 To deViews.Items.C ount - 1
Dim opchk As String = deViews.Items(i ).Value
Dim chk = deViews.DataVal ueField
If opchk = Session("typeof option") Then
deViews.Items(i ).Selected = True
End If
Next
End Sub 3 2030
On what line does the error occur?
"Stanley J Mroczek" wrote: 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:TemplateCo lumn runat="server" HeaderText="Id Type Option" SortExpression= "IdTypeOpti on"> <itemtemplate > <asp:label runat="server" Text='<%# DataBinder.Eval (Container.Data Item, "TypeOption ") %>' /> <asp:label runat="server" ID="LlbTypeOpti on" Visible=False Text='<%# DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>'/> </itemtemplate> <EditItemTempla te> <asp:dropdownli st id="deViews" OnDataBinding=" loaddd" runat="server"> </asp:dropdownlis t> <asp:label runat="server" ID="IdTypeOptio n" Visible=False Text='<%# DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>' /> </EditItemTemplat e> </asp:TemplateCol umn>
Sub loaddd(ByVal sender As Object, ByVal e As System.EventArg s)
Dim myConnection As SqlConnection = New SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring")) Dim myCommand As SqlCommand = New SqlCommand("Get _All_TypeofOpti ons", myConnection)
Dim dtrControlOptio n As New DataTable Dim dropRowOption As DataRow
dtrControlOptio n.Columns.Add( _ New DataColumn("Typ eOption", GetType(String) ))
dtrControlOptio n.Columns.Add( _ New DataColumn("IdT ypeOption", GetType(String) ))
myConnection.Op en()
Dim Optionfile As SqlDataReader = myCommand.Execu teReader(Comman dBehavior.Close Connection)
While Optionfile.Read () dropRowOption = dtrControlOptio n.NewRow() dropRowOption(" TypeOption") = Optionfile.Item ("TypeOption ") dropRowOption(" IdTypeOption") = Optionfile.Item ("IdTypeOption" ) dtrControlOptio n.Rows.Add(drop RowOption)
End While
deViews.DataSou rce = dtrControlOptio n deViews.DataTex tField = "TypeOption " deViews.DataVal ueField = "IdTypeOpti on" deViews.DataBin d()
myConnection.Cl ose() BindOption() Dim i As Integer For i = 0 To deViews.Items.C ount - 1 Dim opchk As String = deViews.Items(i ).Value Dim chk = deViews.DataVal ueField If opchk = Session("typeof option") Then deViews.Items(i ).Selected = True End If Next
End Sub
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.NullRefe renceException: Object reference not set
to an instance of an object.
Source Error:
Line 211: End While
Line 212:
Line 213: deViews.DataSou rce = dtrControlOptio n
Line 214: deViews.DataTex tField = "TypeOption "
Line 215: deViews.DataVal ueField = "IdTypeOpti on"
Source File: C:\best\_Option Maint.ascx.vb Line: 213
"pm" wrote: On what line does the error occur?
"Stanley J Mroczek" wrote:
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:TemplateCo lumn runat="server" HeaderText="Id Type Option" SortExpression= "IdTypeOpti on"> <itemtemplate > <asp:label runat="server" Text='<%# DataBinder.Eval (Container.Data Item, "TypeOption ") %>' /> <asp:label runat="server" ID="LlbTypeOpti on" Visible=False Text='<%# DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>'/> </itemtemplate> <EditItemTempla te> <asp:dropdownli st id="deViews" OnDataBinding=" loaddd" runat="server"> </asp:dropdownlis t> <asp:label runat="server" ID="IdTypeOptio n" Visible=False Text='<%# DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>' /> </EditItemTemplat e> </asp:TemplateCol umn>
Sub loaddd(ByVal sender As Object, ByVal e As System.EventArg s)
Dim myConnection As SqlConnection = New SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring")) Dim myCommand As SqlCommand = New SqlCommand("Get _All_TypeofOpti ons", myConnection)
Dim dtrControlOptio n As New DataTable Dim dropRowOption As DataRow
dtrControlOptio n.Columns.Add( _ New DataColumn("Typ eOption", GetType(String) ))
dtrControlOptio n.Columns.Add( _ New DataColumn("IdT ypeOption", GetType(String) ))
myConnection.Op en()
Dim Optionfile As SqlDataReader = myCommand.Execu teReader(Comman dBehavior.Close Connection)
While Optionfile.Read () dropRowOption = dtrControlOptio n.NewRow() dropRowOption(" TypeOption") = Optionfile.Item ("TypeOption ") dropRowOption(" IdTypeOption") = Optionfile.Item ("IdTypeOption" ) dtrControlOptio n.Rows.Add(drop RowOption)
End While
deViews.DataSou rce = dtrControlOptio n deViews.DataTex tField = "TypeOption " deViews.DataVal ueField = "IdTypeOpti on" deViews.DataBin d()
myConnection.Cl ose() BindOption() Dim i As Integer For i = 0 To deViews.Items.C ount - 1 Dim opchk As String = deViews.Items(i ).Value Dim chk = deViews.DataVal ueField If opchk = Session("typeof option") Then deViews.Items(i ).Selected = True End If Next
End Sub
Once a control is in a grid you can't address it using its id but have to get
a reference to it using FindControl.
This is close to what you need to do but you will have to play around with
it a bit (its in C# sorry.
DropDownList tmpDDL = new DropDownList();
tmpDDL = e.Item.FindCont rol("deViews");
if (tmpDDL!=null) //here for testing mostly
{
.. . . manipulate the dataview
}
Don't forget that at the beginning of your load event you want to check if
you are on an Item or Alternating Item (hence the if (tmpDDL!=null). You
won't be able to find the DropDownList on the Header and the Footer. There
is an enum for ItemTypes you can use.
Let me know how it goes.
"Stanley J Mroczek" wrote: 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.NullRefe renceException: Object reference not set to an instance of an object.
Source Error:
Line 211: End While Line 212: Line 213: deViews.DataSou rce = dtrControlOptio n Line 214: deViews.DataTex tField = "TypeOption " Line 215: deViews.DataVal ueField = "IdTypeOpti on"
Source File: C:\best\_Option Maint.ascx.vb Line: 213
"pm" wrote:
On what line does the error occur?
"Stanley J Mroczek" wrote:
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:TemplateCo lumn runat="server" HeaderText="Id Type Option" SortExpression= "IdTypeOpti on"> <itemtemplate > <asp:label runat="server" Text='<%# DataBinder.Eval (Container.Data Item, "TypeOption ") %>' /> <asp:label runat="server" ID="LlbTypeOpti on" Visible=False Text='<%# DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>'/> </itemtemplate> <EditItemTempla te> <asp:dropdownli st id="deViews" OnDataBinding=" loaddd" runat="server"> </asp:dropdownlis t> <asp:label runat="server" ID="IdTypeOptio n" Visible=False Text='<%# DataBinder.Eval (Container.Data Item, "IdTypeOpti on") %>' /> </EditItemTemplat e> </asp:TemplateCol umn>
Sub loaddd(ByVal sender As Object, ByVal e As System.EventArg s)
Dim myConnection As SqlConnection = New SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring")) Dim myCommand As SqlCommand = New SqlCommand("Get _All_TypeofOpti ons", myConnection)
Dim dtrControlOptio n As New DataTable Dim dropRowOption As DataRow
dtrControlOptio n.Columns.Add( _ New DataColumn("Typ eOption", GetType(String) ))
dtrControlOptio n.Columns.Add( _ New DataColumn("IdT ypeOption", GetType(String) ))
myConnection.Op en()
Dim Optionfile As SqlDataReader = myCommand.Execu teReader(Comman dBehavior.Close Connection)
While Optionfile.Read () dropRowOption = dtrControlOptio n.NewRow() dropRowOption(" TypeOption") = Optionfile.Item ("TypeOption ") dropRowOption(" IdTypeOption") = Optionfile.Item ("IdTypeOption" ) dtrControlOptio n.Rows.Add(drop RowOption)
End While
deViews.DataSou rce = dtrControlOptio n deViews.DataTex tField = "TypeOption " deViews.DataVal ueField = "IdTypeOpti on" deViews.DataBin d()
myConnection.Cl ose() BindOption() Dim i As Integer For i = 0 To deViews.Items.C ount - 1 Dim opchk As String = deViews.Items(i ).Value Dim chk = deViews.DataVal ueField If opchk = Session("typeof option") Then deViews.Items(i ).Selected = True End If Next
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 Description"></asp:BoundColumn>
<asp:TemplateColumn runat="server" HeaderText="Id Type Option" ">
<itemtemplate>
<asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem,
"TypeOption") %>' />
|
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 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...
|
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 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,
|
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"
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,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |