Need assistance with Detailsview and passing values to a textbox

A

ajmister

Hi
I have a Multiview with two views. Both views each have a
detailsview control with several textbox's and
AutoGenerateEditButton="True".
During Update I am trying to insert a value to the product textbox
based on the option chosen from a dropdown but am having problems.
Could someone please help.

The error is for
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Source Error:


Line 545:
DirectCast(DTLTrainUpdateVw.FindControl("txtTrainProduct"),
TextBox).Text = product
Line 546:

I get the following message while running on a debug mode " Use the
"New" keyword to create an object instance" for the above line.

My .aspx code

<table >
<tr valign="top" >
<td>
<asp:Label id="LblResponseAcct" runat="server"
Text="Account to Update"/>
</td>
<td align="center">
<asp:DropDownList
ID="DDLUpdateSubAcctView"
runat="server" AutoPostBack="true"
OnSelectedIndexChanged =
"DDLUpdateSubAcctView_SelectedIndexChanged"</asp:DropDownList>
</td>
<td align="left">
<asp:Label id="LblResponseProd" runat="server"
Text="Choose Product" />
</td>
<td align="center">
<asp:DropDownList
ID="DDLUpdateSubView"
runat="server"
AppendDataBoundItems="True"
AutoPostBack="true"

OnSelectedIndexChanged="DDLUpdateSubView_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
<table >
<tr valign="top" >
<td>

<asp:DetailsView ID="DTLTrainUpdateVw" runat="server"
CellPadding="4"
visible = "false"
AutoGenerateRows="false"
GridLines="Horizontal"
ForeColor="#333333"
AllowPaging="false"
Font-names= "Mangal"
Font-size = "Medium"
AutoGenerateEditButton="True"
OnModeChanging="DTLTrainUpdateVw_ModeChanging"
OnItemUpdating="DTLTrainUpdateVw_ItemUpdating"
onitemupdated="DTLTrainUpdateVw_ItemUpdated"
OnModeChanged="DTLTrainUpdateVw_ModeChanged"<FieldHeaderStyle BackColor="Gray" Font-Bold="True" Font-
Names="Mangal"
Font-Strikeout="False" />
<HeaderStyle BackColor="#999999" Font-Bold="True"
ForeColor="White"/>
<AlternatingRowStyle BackColor="White"/>
<Fields>
<asp:TemplateField HeaderText = "PRODUCT:">
<ItemTemplate>
<asp:TextBox ID="TxtTrainProduct" runat
="server">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "ACCOUNT:">
<ItemTemplate>
<asp:Label ID = "LblIMGUpdateAcct"
runat="server" Text='<%# eval("acct")%>' />
</ItemTemplate>
</asp:TemplateField>
..........................
..........................
</Fields>
</asp:DetailsView>
</td>
</tr>

<tr>
<td>

<asp:DetailsView ID="DTLAircraftUpdateVw" runat="server"
CellPadding="4"
visible = "false"
AutoGenerateRows="false"
..........................
..........................<Fields>
<asp:TemplateField HeaderText = "PRODUCT:">
<ItemTemplate>
<asp:TextBox ID="TxtAircraftProduct" runat
="server">
</asp:TextBox>
</ItemTemplate>
..........................
..........................
</Fields>
</asp:DetailsView>
</td>
</tr>
</table>


VB code behind
..aspx.vb
Protected Sub DDLUpdateSubView_SelectedIndexChanged(ByVal sender
As Object, ByVal e As System.EventArgs)
Dim acct As String =
Trim(DDLUpdateSubAcctView.SelectedItem.Text)
Dim product As String =
Trim(DDLUpdateSubView.SelectedItem.Text)

Dim StrSql As String
StrSql = "Select * from df_" & product & "_profile_tbl where
acct =
'" & acct & "'"

Dim SqlCmd As New SqlCommand(StrSql, dbconn)
Dim ada As New SqlDataAdapter(SqlCmd)
Dim ds As New DataSet()

If product = "TRAINS" Then
MltVwFeedClient.SetActiveView(UpdateTrainView)
// Insert PRODUCT Value to the Product TextBOX
DirectCast(DTLTrainUpdateVw.FindControl("TxtTrainProduct"),
TextBox).Text = product
Try
dbconn.Open()
ada.Fill(ds)
DTLTrainUpdateVw.DataSource = ds
DTLTrainUpdateVw.DataBind()
dbconn.Close()
Catch ex As Exception
End Try
ElseIf product = "HISTORY" Then
MltVwFeedClient.SetActiveView(UpdateAircraftView)

DirectCast(DTLAircraftUpdateVw.FindControl("TxtAircraftProduct"),
TextBox).Text = product
Try
dbconn.Open()
ada.Fill(ds)
DTLAircraftUpdateVw.DataSource = ds
DTLAircraftUpdateVw.DataBind()
dbconn.Close()
Catch ex As Exception
End Try
End If
End Sub
 

Ask a Question

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

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

Ask a Question

Top