Declaring controls in FormView

P

photo

Hi!

I am new to .net (vb) and moving from classic asp. I ran into a problem
that has left me with less hair on my head.

For some reason, my button and calendar that sits inside an
insertItemTemplate in a FormView, will not allow me to declare it. The
controls (Calendar1, InvoiceDate) are in the page and names are
correct. Here is the sub I am using.

<script language="VB" runat="server">

' when the button is clicked the calendar is visible

Sub showcal1(ByVal sender As Object, ByVal e As EventArgs)
Calendar1.Visible = True
End Sub
' this takes the date selected from the calendar and places it in a
textbox.
Sub Date_Selected(ByVal sender As Object, ByVal e As EventArgs)
InvoiceDate.Text = Calendar1.SelectedDate.ToShortDateString
Calendar1.Visible = False
End Sub

</script>

This works fine if it is not inside the FormView control. I am using
inline code for this task. Below is the entire of code. Any help would
be greatly appreciated. ; )


<script language="VB" runat="server">

' when the button is clicked the calendar is visible

Sub showcal1(ByVal sender As Object, ByVal e As EventArgs)
Calendar1.Visible = True
End Sub
' this takes the date selected from the calendar and places it in a
textbox.
Sub Date_Selected(ByVal sender As Object, ByVal e As EventArgs)
InvoiceDate.Text = Calendar1.SelectedDate.ToShortDateString
Calendar1.Visible = False
End Sub

</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link href="ts.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<table align="center" bgcolor="#ffffff" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td style="height: 10px">
<img id="interface_r1_c5" alt="" border="0"
height="10" name="interface_r1_c5"
src="assets/layout/images/interface_r1_c5.gif"
width="10" /></td>
<td style="height: 10px">
<img id="interface_r1_c6" alt="" border="0"
height="10" name="interface_r1_c6"
src="assets/layout/images/interface_r1_c6.gif"
width="620" /></td>
<td style="height: 10px">
<img id="interface_r1_c7" alt="" border="0"
height="10" name="interface_r1_c7"
src="assets/layout/images/interface_r1_c7.gif"
width="10" /></td>
</tr>
<tr>
<td
background="assets/layout/images/interface_r2_c5.gif">
<img id="interface_r2_c5" alt="" border="0"
height="70" name="interface_r2_c5"
src="assets/layout/images/interface_r2_c5.gif"
width="10" /></td>
<td bgcolor="#ffffff" class="content" valign="top">
<h2>
Invoicer</h2>

<p>&nbsp;</p>
<p>
&nbsp;<asp:AccessDataSource
ID="AccessDataSource1" runat="server" DataFile="~/db/db.MDB"
SelectCommand="SELECT * FROM [tblInvoice]"
DeleteCommand="DELETE FROM [tblInvoice] WHERE [ID] = ?"
InsertCommand="INSERT INTO [tblInvoice] ([ID], [Client], [InvoiceDate],
[ServiceType], [TotalHours], [HourlyRate], [Archived]) VALUES (?, ?, ?,
?, ?, ?, ?)" UpdateCommand="UPDATE [tblInvoice] SET [Client] = ?,
[InvoiceDate] = ?, [ServiceType] = ?, [TotalHours] = ?, [HourlyRate] =
?, [Archived] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32"
/>
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Client"
Type="String" />
<asp:parameter Name="InvoiceDate"
Type="DateTime" />
<asp:parameter Name="ServiceType"
Type="String" />
<asp:parameter Name="TotalHours"
Type="Int32" />
<asp:parameter Name="HourlyRate"
Type="Decimal" />
<asp:parameter Name="Archived"
Type="Boolean" />
<asp:parameter Name="ID" Type="Int32"
/>
</UpdateParameters>
<InsertParameters>





<asp:parameter Name="ID" Type="Int32"
/>
<asp:parameter Name="Client"
Type="String" />
<asp:parameter Name="InvoiceDate"
Type="DateTime" />
<asp:parameter Name="ServiceType"
Type="String" />
<asp:parameter Name="TotalHours"
Type="Int32" />
<asp:parameter Name="HourlyRate"
Type="Decimal" />
<asp:parameter Name="Archived"
Type="Boolean" />
</InsertParameters>
</asp:AccessDataSource>
</p>
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="ID" DataSourceID="AccessDataSource1">
<EditItemTemplate>



ID:
<asp:Label ID="IDLabel1" runat="server"
Text='<%# Eval("ID") %>'></asp:Label><br />
Client:
<asp:TextBox ID="ClientTextBox"
runat="server" Text='<%# Bind("Client") %>'>
</asp:TextBox><br />
InvoiceDate:
<asp:TextBox ID="InvoiceDateTextBox"
runat="server" Text='<%# Bind("InvoiceDate") %>'>
</asp:TextBox><br />
ServiceType:
<asp:TextBox ID="ServiceTypeTextBox"
runat="server" Text='<%# Bind("ServiceType") %>'>
</asp:TextBox><br />
TotalHours:
<asp:TextBox ID="TotalHoursTextBox"
runat="server" Text='<%# Bind("TotalHours") %>'>
</asp:TextBox><br />
HourlyRate:
<asp:TextBox ID="HourlyRateTextBox"
runat="server" Text='<%# Bind("HourlyRate") %>'>
</asp:TextBox><br />
Archived:
<asp:CheckBox ID="ArchivedCheckBox"
runat="server" Checked='<%# Bind("Archived") %>' /><br />
<asp:LinkButton ID="UpdateButton"
runat="server" CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>



<table>
<tr>
<td >
Client:</td>
<td style="width: 233px" >
<asp:TextBox ID="Client"
runat="server"></asp:TextBox></td>
</tr>
<tr>
<td valign="top">
Date:</td>
<td valign="top" style="width: 233px">
<asp:TextBox ID="InvoiceDate" runat="server"
Width="57px" ReadOnly="True"></asp:TextBox>
<asp:Button ID="Button1" onClick="showcal1"
runat="server" Text="Date Picker" Width="33px" />
<br />
<asp:Calendar ID="Calendar1"
onselectionchanged="Date_Selected" runat="server"
Visible="False"></asp:Calendar> </td>
</tr>
<tr>
<td >
Type of service</td>
<td style="width: 233px" >
<asp:TextBox ID="ServiceType"
runat="server" Width="224px"></asp:TextBox></td>
</tr>
<tr>
<td >
Hours</td>
<td style="width: 233px" >
<asp:TextBox ID="TotalHours"
runat="server" Width="56px"></asp:TextBox></td>
</tr>
<tr>
<td >
Hourly Rate</td>
<td style="width: 233px" >
<asp:TextBox ID="HourlyRate"
runat="server"></asp:TextBox></td>
</tr>
<tr>
<td >&nbsp;</td>
<td style="width: 233px" ><asp:Button
ID="Button2" Text="Submit" runat="server" /></td>
</tr>
</table>
<br />
<asp:LinkButton ID="InsertButton"
runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton"
runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
ID:
<asp:Label ID="IDLabel" runat="server"
Text='<%# Eval("ID") %>'></asp:Label><br />
Client:
<asp:Label ID="ClientLabel" runat="server"
Text='<%# Bind("Client") %>'></asp:Label><br />
InvoiceDate:
<asp:Label ID="InvoiceDateLabel"
runat="server" Text='<%# Bind("InvoiceDate") %>'></asp:Label><br />
ServiceType:
<asp:Label ID="ServiceTypeLabel"
runat="server" Text='<%# Bind("ServiceType") %>'></asp:Label><br />
TotalHours:
<asp:Label ID="TotalHoursLabel"
runat="server" Text='<%# Bind("TotalHours") %>'></asp:Label><br />
HourlyRate:
<asp:Label ID="HourlyRateLabel"
runat="server" Text='<%# Bind("HourlyRate") %>'></asp:Label><br />
Archived:
<asp:CheckBox ID="ArchivedCheckBox"
runat="server" Checked='<%# Bind("Archived") %>'
Enabled="false" /><br />
<asp:LinkButton ID="EditButton"
runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="DeleteButton"
runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
<asp:LinkButton ID="NewButton"
runat="server" CausesValidation="False" CommandName="New"
Text="New"></asp:LinkButton>
</ItemTemplate>
</asp:FormView>

</td>
<td
background="assets/layout/images/interface_r2_c7.gif">
<img id="interface_r2_c7" alt="" border="0"
height="70" name="interface_r2_c7"
src="assets/layout/images/interface_r2_c7.gif"
width="10" /></td>
</tr>
<tr>
<td >
<img id="interface_r3_c5" alt="" border="0"
height="10" name="interface_r3_c5"
src="assets/layout/images/interface_r3_c5.gif"
width="10" /></td>
<td >
<img id="interface_r3_c6" alt="" border="0"
height="10" name="interface_r3_c6"
src="assets/layout/images/interface_r3_c6.gif"
width="620" /></td>
<td >
<img id="interface_r3_c7" alt="" border="0"
height="10" name="interface_r3_c7"
src="assets/layout/images/interface_r3_c7.gif"
width="10" /></td>
</tr>
</table>
</form>
</body>
</html>
 
U

ultraweaver

Got it.... had to dim them up and add FindControl...

Sub showcal1(ByVal sender As Object, ByVal e As EventArgs)
FormView1.FindControl("Calendar1").Visible = True
End Sub

Sub Date_Selected(ByVal sender As Object, ByVal e As EventArgs)

Dim invdate
invdate = FormView1.FindControl("InvoiceDate")
Dim clnd
clnd = FormView1.FindControl("Calendar1")

invdate.text = clnd.SelectedDate.ToShortDateString()
FormView1.FindControl("Calendar1").Visible = False

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

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top