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

Help needed - nested detailsview referencing

P: 1
Hi,

I have a page which is basically a details view(in inset mode) inside a datalist.
The problem is I want to set the field "invoiceID" (of the detailsview) to an invoiceID coming through the query string of the page.

Now, I have sucessfully done this with a detailsview that is not enclosed in a datalist, using the following page load script:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim Invoiceid As TextBox = CType(DetailsView1.FindControl("Invoiceid"), TextBox)
Invoiceid.Text = Request.QueryString("Invoiceid")
End Sub



however when I enclosed the detailsview in a datalist, it suddenly stopped working,

The first error I get is

Compiler Error Message: BC30451: Name 'DetailsView1' is not declared.

Line 9: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 10:
Line 11: Dim Invoiceid As TextBox = CType(DetailsView1.FindControl("Invoiceid"), TextBox)
Line 12: Invoiceid.Text = Request.QueryString("Invoiceid")
Line 13: End Sub



My code is below:



<asp:DataList ID="DataList1" runat="server" DataKeyField="TestID" DataSourceID="ObjectDataSource2"
Style="z-index: 120; left: 32px; position: absolute; top: 162px">
<ItemTemplate>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="TestID"
DataSourceID="ObjectDataSource1" Style="position: static">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="TestID" HeaderText="TestID" InsertVisible="False" ReadOnly="True"
SortExpression="TestID" />
<asp:BoundField DataField="InvoiceID" HeaderText="InvoiceID" SortExpression="InvoiceID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />
</Columns>
</asp:GridView>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="DataSet1TableAdapters.TestTableAdapter" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_TestID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="InvoiceID" Type="Int32" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
<asp:Parameter Name="Original_TestID" Type="Int32" />
<asp:Parameter Name="TestID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="InvoiceID" QueryStringField="InvoiceID"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="InvoiceID" Type="Int32" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="TestID"
DataSourceID="ObjectDataSource1" Height="50px" Style="position: static" Width="125px" DefaultMode="Insert">
<Fields>
<asp:BoundField DataField="TestID" HeaderText="TestID" InsertVisible="False" ReadOnly="True" SortExpression="TestID" />
<asp:CommandField ShowInsertButton="True" />

<asp:TemplateField >
<InsertItemTemplate>
<asp:TextBox ID="InvoiceID" runat="server" Text='<%# Bind("InvoiceID") %>' Visible="false"></asp:TextBox>
<asp:TextBox ID="FirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
<asp:TextBox ID="Surname" runat="server" Text='<%# Bind("Surname") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>

</Fields>
</asp:DetailsView>


</ItemTemplate>
</asp:DataList>


<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" DeleteMethod="Delete"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="DataSet1TableAdapters.TestTableAdapter" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_TestID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="InvoiceID" Type="Int32" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
<asp:Parameter Name="Original_TestID" Type="Int32" />
<asp:Parameter Name="TestID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="InvoiceID" QueryStringField="InvoiceID"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="InvoiceID" Type="Int32" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>


Can anyone tell me how to reference the Invoice ID textbox in the detailsview, and then set it to a request.querystring value?

thanks
Mar 16 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.