in the design view i can see the repeater, but in the browser the repeater is not showing at all.
created a repeater and can not render it. When we inspect the object, it does not appear. I took the code above it , called analyze registration data and repeat after the repeater and can not see , but the repeater not. What could be wrong ? Below the code from analyze registration data :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:GridView ID="GridView1" ShowHeader="false"
GridLines="None" AutoGenerateColumns="false"
runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table style="border: 1px solid #A55129;
background-color: #FFF7E7">
<tr>
<td style="width: 200px">
<asp:Image ID="imgEmployee"
ImageUrl='<%# Eval("PhotoPath")%>'
runat="server" />
</td>
<td style="width: 200px">
<table>
<tr>
<td>
<b>Id:</b>
</td>
<td>
<asp:Label ID="lblId"
runat="server"
Text='<%#Eval("EmployeeId") %>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<asp:Label ID="lblName"
runat="server"
Text='<%#Eval("Name") %>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Gender:</b>
</td>
<td>
<asp:Label ID="lblGender"
runat="server"
Text='<%#Eval("Gender") %>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>City:</b>
</td>
<td>
<asp:Label ID="lblCity"
runat="server"
Text='<%#Eval("City") %>'>
</asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
<td>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table style="border: 1px solid #A55129;
background-color: #FFF7E7">
<tr>
<td style="width: 200px">
<asp:Image ID="imgEmployee"
ImageUrl='<%# Eval("PhotoPath")%>'
runat="server" />
</td>
<td style="width: 200px">
<table>
<tr>
<td>
<b>Id:</b>
</td>
<td>
<asp:Label ID="lblId"
runat="server"
Text='<%#Eval("EmployeeId") %>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Name:</b>
</td>
<td>
<asp:Label ID="lblName"
runat="server"
Text='<%#Eval("Name") %>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>Gender:</b>
</td>
<td>
<asp:Label ID="lblGender"
runat="server"
Text='<%#Eval("Gender") %>'>
</asp:Label>
</td>
</tr>
<tr>
<td>
<b>City:</b>
</td>
<td>
<asp:Label ID="lblCity"
runat="server"
Text='<%#Eval("City") %>'>
</asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
<SeparatorTemplate>
<asp:Image ID="Image1"
ImageUrl="~/Images/1x1PixelImage.png"
runat="server" />
</SeparatorTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>
//////////////////
Imports System.Data.SqlClient
Public Class WebForm2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim con As SqlConnection = New SqlConnection("data source=.; database=image; integrated security=SSPI")
Dim cmd As SqlCommand = New SqlCommand("Select * from tblEmployee", con)
con.Open()
Dim rdr As SqlDataReader = cmd.ExecuteReader()
GridView1.DataSource = rdr
GridView1.DataBind()
Repeater1.DataSource = rdr
Your repeater needs a datasource and then you need to call DataBind.
Repeater1.DataSource = rdr
Repeater1.DataBind()
I'd recommend that you wrap that in a Not IsPostBack conditional as well
if Not IsPostback
Repeater1.DataSource = rdr
Repeater1.DataBind()
GridView1.DataSource = rdr
GridView1.DataBind()
Repeater1.DataSource = rdr
Repeater1.DataBind()
Related
I got a problem with getting the correct value (checked true/false) of my radiobuttons inside nested repeaters.
VIEW
<table id="HoursTable">
<asp:Repeater ID="hoursRepeater" runat="server">
<HeaderTemplate>
<thead>
<tr>
<th>V</th>
<th>some text</th>
<th>some text</th>
<th>some text</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr runat="server" ID="itemTemplateRow">
<td runat="server" visible="false">
<asp:HiddenField runat="server" ID="HoursIDHiddenField" Value='<%# Eval("HoursID") %>' />
</td>
<td class="centerAlign">
<input runat="server" type="radio" class="radiobuttonMain" ID="aprrovalRadioButton" Checked='<%# DataBinder.Eval(Container.DataItem, "IsApproved") %>' />
</td>
<td>some text</td>
<td>some text</td>
</tr>
<asp:Repeater runat="server" ID="temporaryHoursRepeater" OnItemDataBound="temporaryHoursRepeater_ItemDataBound">
<ItemTemplate>
<tr runat="server" ID="itemTemplateRow">
<td runat="server" visible="false">
<asp:HiddenField runat="server" ID="HoursIDHiddenField" Value='<%# Eval("HoursID") %>' />
</td>
<input runat="server" type="radio" class="radiobuttonTemp" ID="aprrovalRadioButton" Checked='<%# DataBinder.Eval(Container.DataItem, "IsApproved") %>'/>
<td>some text</td>
<td>some text</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</table>
<tr>
<td>
<asp:Button runat="server" ID="saveButton" CssClass="saveButton" Text="Save" OnClick="saveButton_Click" />
</td>
</tr>
CODE BEHIND
Protected Sub saveButton_Click(sender As Object, e As EventArgs)
For Each rptItem As RepeaterItem In urenRepeater.Items
Dim currentHoursGroup As New List(Of Hour)
currentHoursGroup.Add(DomainController.getInstance.getHour(CType(rptItem.FindControl("HoursIDHiddenField"), HiddenField).Value))
For Each rptItemC As RepeaterItem In CType(rptItem.FindControl("temporaryUrenRepeater"), Repeater).Items
currentHoursGroup.Add(DomainController.getInstance.getHour(CType(rptItemC.FindControl("HoursIDHiddenField"), HiddenField).Value))
Next
If DirectCast(rptItem.FindControl("approvalRadioButton"), HtmlInputRadioButton).Checked Then
currentHoursGroup.Remove(DomainController.getInstance.getHour(CType(rptItem.FindControl("HoursIDHiddenField"), HiddenField).Value))
DomainController.getInstance.getHour(CType(rptItem.FindControl("HoursIDHiddenField"), HiddenField).Value).deleteAllTemporaryHours()
Else
For Each rptItemT As RepeaterItem In CType(rptItem.FindControl("temporaryUrenRepeater"), Repeater).Items
If DirectCast(rptItemT.FindControl("approvalRadioButton"), HtmlInputRadioButton).Checked Then
currentHoursGroup.Remove(DomainController.getInstance.getHour(CType(rptItemT.FindControl("HoursIDHiddenField"), HiddenField).Value))
'do sth
End If
Next
End If
For Each u As Hour In currentHoursGroup
'do sth
Next
Next
End Sub
The problem is that 'DirectCast(rptItem.FindControl("approvalRadioButton"), HtmlInputRadioButton).Checked' always returns false, even it is checked.
I did hours of research, but I can't figure out what I'm doing wrong here
I found a workaround to reach what I want.
I added in each row a hiddenfield and gave it the following attribute:
Value='<%# DataBinder.Eval(Container.DataItem, "IsApproved").ToString %>'
Then I wrote some javascript to change the value (true/false) of the hiddenfield if a radiobutton was pressed.
In the code behind I check from every repeateritem the value of the hiddenfield and I got my selected rows!
I have a formview that binds to an Entity Framework datasource using the following code:
Private Sub LoadFormviewData()
Dim ctx As New SNOTEntities
Dim RepCalls = ctx.SNOT_RepCall_view
Dim strSQL As New StringBuilder
strSQL.Append("select * from SNOT_RepCall_view where DateInput >= '")
strSQL.Append(Startdate.ToShortDateString)
strSQL.Append("' and DateInput <= '")
strSQL.Append(EndDate.ToShortDateString)
If IncReviewed = "N" Then
strSQL.Append("' and Reviewed = 'N'")
Else
strSQL.Append("'")
End If
strSQL.Append(" order by IssueID")
Dim calls = RepCalls.SqlQuery(strSQL.ToString)
FormView1.DataSource = calls.ToList
FormView1.DataBind()
If 1 = 1 Then
End If
End Sub
Using the AllowPaging=true I find that it skips every other record when paging. I am new to EF and not that good at ASP.net so forgive me if you require any more info.
I use the IndexChanging and Indexchanged events to save/populate fields that are outside of the formview (too much code to post unless requested)
I have confirmed that the correct amount of records are in 'calls' and that they make it into the Formview datasource. It just skips every other record when paging. Have stared at this code for days. Any help/suggestions welcome.
Formview markup:
<asp:FormView ID="FormView1" runat="server" Height="521px" Width="375px" HorizontalAlign="Left" AllowPaging="True">
<ItemTemplate>
<asp:label ID="HiddenField1" runat="server" Text='<%#Eval("IssueID")%>'/>
<asp:Label ID="Label12" runat="server" Text="<%# FormView1.PageIndex%>"></asp:Label>
<table border="1" style="width: 375px; ">
<tr>
<td><asp:Label ID="Label3" runat="server" CssClass="LabelBold" Text="Call Date:"></asp:Label>
<asp:Label ID="lblCallDate" runat="server" CssClass="LabelNormal" Text='<%#Eval("CallDate", "{0:dd/M/yyyy}")%>'></asp:Label>
</td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" CssClass="LabelBold" Text='Input Date:'></asp:Label>
<asp:Label ID="lblInputDate" runat="server" CssClass="LabelNormal" Text='<%#Eval("DateInput", "{0:dd/M/yyyy}")%>'></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label11" runat="server" CssClass="LabelBold" Text='<%#Eval("IssueTypeName")%>'></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblStore" runat="server" CssClass="LabelBold" Text='<%#Eval("StoreName")%>'></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" CssClass="LabelBold" Text="Rep:"></asp:Label>
<asp:Label ID="lblRep" runat="server" CssClass="LabelNormal" Text='<%#Eval("InputByName")%>'></asp:Label>
</td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="lblCust" runat="server" CssClass="LabelBold" Text='<%#Eval("CustName")%>'></asp:Label>
</td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" CssClass="LabelBold" Text="Vendor:"></asp:Label>
<asp:Label ID="lblVendor" runat="server" CssClass="LabelNormal" Text='<%#Eval("Vendor")%>'></asp:Label>
</td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" CssClass="LabelBold" Text="Rep Notes:"></asp:Label>
<br />
<asp:Label ID="lblDetails" runat="server" CssClass="LabelNormal" Text='<%#Eval("Details")%>'></asp:Label>
</td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" CssClass="LabelBold" Text="Reviewer Notes:"></asp:Label>
<br />
<asp:TextBox ID="txtRevNotes" runat="server" Height="130px" TextMode="MultiLine" Width="345px" Text='<%#Eval("ReviewerNotes")%>' ReadOnly="True"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</ItemTemplate>
<EmptyDataTemplate>
There is nothing to see here.
</EmptyDataTemplate>
<PagerSettings Position="TopAndBottom" Mode="NumericFirstLast" />
<%-- <PagerTemplate>
<table style="border: thin solid #000000; width: 375px;">
<tr>
<td style="width: 80px" >
<%-- <asp:linkButton
id="lnkPrevious"
Text="Prev"
CommandName="Page"
CommandArgument="Prev"
Runat="server" />
</td>
<td style="font-family: Arial, Helvetica, sans-serif; text-align: center; width: 215px">
<asp:Label ID="Label8" runat="server" Text="<%# FormView1.PageCount - FormView1.PageIndex -1%>"></asp:Label>
more to go
</td>
<td style="width: 80px">
<asp:linkButton
id="lnkNext"
Text="Next"
CommandName="Page"
CommandArgument="Next"
Runat="server" />
</td>
</tr>
</table>
</PagerTemplate>--%>
</asp:FormView>
The pagertemplate is commented out as part of my testing leaving just the default version.
I have a datalist and a binddata Sub in vb side that works on page load and I can see all my data but then when I click edit it brings up this error:-
Invalid postback or callback argument. Event validation is enabled using in configuration or <%# Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Here is My vb code:-
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
BindData()
End Sub
Protected Sub BindData()
Dim cn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
cmd.Connection = cn
cmd.CommandText = "SELECT DISTINCT Users.User_ID, Users.FirstName, Users.LastName, Users.Password, Users.Email, Users.ContactNum, Users.Address, Users.County, Users.Gender, Users.Datejoined, Users.Dateleft, Users.Subscription_ID, Subscriptions.Subscription_type FROM Users INNER JOIN Subscriptions ON Users.Subscription_ID = Subscriptions.Subscription_ID WHERE (Users.Dateleft IS NULL)"
cn.Open()
Dim ds As SqlDataReader
ds = cmd.ExecuteReader()
MyDataList.DataSource = ds
MyDataList.DataBind()
cn.Close()
End Sub
Sub myDataList_EditCommand(sender As Object, e As DataListCommandEventArgs) Handles MyDataList.EditCommand
BindData()
MyDataList.EditItemIndex = e.Item.ItemIndex
End Sub
And this is my asp.net :-
<asp:DataList ID="MyDataList"
runat="server"
RepeatColumns="2" CellSpacing="-1" Font-Bold="False" Font-Italic="False"
Font-Names="Arial" Font-Overline="False" Font-Size="Medium"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
ShowFooter="False" ShowHeader="False"
onItemDataBound="myDataList_ItemDataBound"
onEditCommand="myDataList_EditCommand"
onCancelCommand="myDataList_CancelCommand"
onUpdateCommand="myDataList_UpdateCommand"
onDeleteCommand="myDataList_DeleteCommand"
RepeatDirection="Horizontal">
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
VerticalAlign="Middle" />
<ItemTemplate>
<br />
<div style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
<table class="style1">
<tr>
<td class="style2">
User ID</td>
<td>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("User_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
Details</td>
<td>
<i><b>
<asp:Label ID="lblFName" runat="server" Text='<%# Eval("FirstName") %>' />
<asp:Label ID="lblLName" runat="server" Text='<%# Eval("LastName") %>' />
</i></b>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="Address" runat="server" Text='<%# Eval("Address") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblCounty" runat="server" Text='<%# Eval("County") %>' />
</td>
</tr>
<tr>
<td class="style2">
Contact Details</td>
<td>
<asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblNum" runat="server" Text='<%# Eval("ContactNum") %>' />
</td>
</tr>
<tr>
<td class="style2">
Package ID</td>
<td>
<asp:Label ID="lblSub" runat="server" Text='<%# Eval("Subscription_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblDes" runat="server" Text='<%# Eval("Subscription_type") %>' />
</td>
</tr>
<tr>
<td class="align-center" colspan="2">
<asp:Button ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="btnDelete" runat="server" CommandName="Delete" Text="Delete" />
</td>
</tr>
</table></div>
<br />
</ItemTemplate>
<EditItemTemplate>
<table class="style1">
<tr>
<td class="style2">
User ID</td>
<td>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("User_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
Details</td>
<td>
<asp:TextBox ID="txtFName" runat="server" text='<%#Container.DataItem("FirstName")%>'></asp:TextBox>
<asp:TextBox ID="txtLName" runat="server" text='<%#Container.DataItem("LastName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style4">
<asp:TextBox ID="lblAdd" runat="server"
text='<%#Container.DataItem("Address")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:TextBox ID="lblCounty" runat="server"
text='<%#Container.DataItem("County")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Contact Details</td>
<td>
<asp:TextBox ID="lblEmail" runat="server"
text='<%#Container.DataItem("Email")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:TextBox ID="lblNum" runat="server"
text='<%#Container.DataItem("ContactNum")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Package ID</td>
<td>
<asp:Label ID="lblSub" runat="server" Text='<%# Eval("Subscription_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblDes" runat="server" Text='<%# Eval("Subscription_type") %>' />
</td>
</tr>
<tr>
<td class="align-center" colspan="2">
<asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update">Update</asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate><SelectedItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
VerticalAlign="Middle" />
I have put Page EnableEventValidation="false" but that just does nothing, i dont tell the error but nothing happens.
Please help me.
Try changing the following code:
Sub myDataList_EditCommand(sender As Object, e As DataListCommandEventArgs) Handles MyDataList.EditCommand
BindData()
MyDataList.EditItemIndex = e.Item.ItemIndex
End Sub
to this
Sub myDataList_EditCommand(sender As Object, e As DataListCommandEventArgs) Handles MyDataList.EditCommand
MyDataList.EditItemIndex = e.Item.ItemIndex
MyDataList.DataBind()
End Sub
I am currently trying to ' Loop ' through my DataGrid to check if the boxes that are ticked to be shown on another page that pretty much looks like my existing one.
I'm having trouble finding out how to actually do a ' loop ' as they are called I think as I am a slow learner in coding , am just looking for some guidance in how I would achieve this goal of actually getting a handle on the Data. Below is my code for the ASP.GridView & well there is no VB.NET code-behind as of such because well , am stuck & need pushing the right direction .
EDIT: Forgot to mention , why cant I do this from a Dim This As String?
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" Width="100%">
<HeaderTemplate>
<table width="100%" style="font-family: Verdana; font-size: 8pt" cellpadding="0"
cellspacing="0" border="1">
<tr align="left">
<th colspan="4">
Customer:
<asp:Label ID="Customer_lab" runat="server"></asp:Label>
</th>
<th colspan="4">
Quote:
<asp:Label ID="Quote_lab" runat="server"></asp:Label>
</th>
<th colspan="4">
Project:
<asp:Label ID="Project_lab" runat="server"></asp:Label></th>
</tr>
<tr>
<th></th>
<th>
CODE
</th>
<th>
DESCRIPTION
</th>
<th>
LENGTH
</th>
<th>
WIDTH
</th>
<th>
QTY
</th>
<th>
COST
</th>
<th>
£M2
</th>
<th>
£UNIT
</th>
<th>
SUPPLIER</th>
<th>
QTY</th>
<th>
DUE DATE</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="ChkItem" runat="server" /></td>
<td style="width: 150px">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Code") %>'></asp:Label></td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Description") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Length") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label6" runat="server" Text='<%# Eval("Width") %>'></asp:Label></td>
<td align="center">
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Qty") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label4" runat="server" Text='<%# Eval("Cost") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label7" runat="server" Text='<%# Eval("M2") %>'></asp:Label></td>
<td align="right">
<asp:Label ID="Label8" runat="server" Text='<%# Eval("SHT") %>'></asp:Label></td>
<td>
<asp:DropDownList ID="DD1" Width="100%" runat="server" Font-Names="Verdana" Font-Size="8pt">
</asp:DropDownList></td>
<td align="left">
<asp:TextBox ID="Qty_Txt1" OnTextChanged="GetData" OnDataBinding='<%# Eval("Code") %>'
AutoPostBack="true" Width="80%" Font-Names="Verdana" Font-Size="8pt" runat="server"></asp:TextBox></td>
<td>
<asp:TextBox ID="Date1" Width="90%" Font-Names="Verdana" Font-Size="8pt" AutoPostBack="true" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td align="center">
<b>
<asp:Label ID="New_Lab" Font-Size="8pt" runat="Server"></asp:Label></b></td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:DropDownList ID="DD2" Width="100%" Font-Names="Verdana" Font-Size="8pt" runat="server">
</asp:DropDownList></td>
<td align="left">
<asp:TextBox ID="Qty_Txt2" AutoPostBack="true" Width="80%" Font-Names="Verdana"
Font-Size="8pt" runat="Server"></asp:TextBox></td>
<td>
<asp:TextBox ID="Date2" Width="90%" Font-Names="Verdana" Font-Size="8pt" runat="Server"></asp:TextBox></td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
<asp:DropDownList ID="DD3" Width="100%" Font-Names="Verdana" Font-Size="8pt" runat="server">
</asp:DropDownList></td>
<td align="left">
<asp:TextBox ID="Qty_Txt3" AutoPostBack="true" Width="80%" Font-Names="Verdana"
Font-Size="8pt" runat="Server"></asp:TextBox></td>
<td width="8%">
<asp:TextBox ID="Date3" Width="90%" Font-Names="Verdana" Font-Size="8pt" runat="Server" ValidationGroup="PersonalInfoGroup">
</asp:TextBox>
<asp:CustomValidator id="RequiredFieldValidator1"
controltovalidate="Date3"
OnServerValidate="Date3_Validator"
errormessage="Date Error!"
runat="Server">
</asp:CustomValidator></td>
</tr>
<asp:HiddenField ID="Supplier" Value='<%# Eval("cdf_supplier_tx") %>' runat="server" />
<asp:HiddenField ID="PrefSupplier" Value='<%# Eval("cdf_supplier_pref") %>' runat="server" />
<asp:HiddenField ID="Nominal" Value='<%# Eval("Nominal") %>' runat="server" />
<asp:HiddenField ID="QuoteCost" Value='<%# Eval("QuoteCost") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<SeparatorStyle BackColor="#C0FFFF" />
<SeparatorTemplate>
</SeparatorTemplate>
</asp:DataList>
EDIT: Some of the VB that's been tried and tested & A little of my own that G_Wilson has tried helping me with but i can't grasp on.
Protected Sub Save_Btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save_Btn.Click
'connection.Open()
'command = New SqlCommand("Select * from impsod_h where [Quote Number]='" + HiddenQno.Value + "'", connection)
'datareader = command.ExecuteReader()
'If datareader.HasRows = False Then
' datareader.Close()
' CreateImpsod1()
' CreateIMPSOH1()
' installcalc()
'Else
' datareader.Close()
'End If
'connection.Close()
For Each Row As GridViewRow In GridView1.Rows
Dim ThisCheck As String
ThisCheck = ChkItem.Checked
Next
End Sub
What i think you will need is a For Each Loop.
That will look a little something like this :
For Each Row as GridViewRow in GridView1.Rows
Dim chkSelect as CheckBox
chkSelect = e.Row.FindControl("ChkItem")
If chkSelect.Checked = True Then
'Put vb.net logic here ...
Else
'Put anything else here ...
End If
Next
That should do the trick.
In the 2nd step of the wizard, I have a dropdownlist that is populated from the db. when I go to the 3rd step RegisterUser.ActiveStepChanged event if fired. In there I save the data to the db. My textboxes are saving properly but my the vb code isn't pulling the selectedIndex/Value from the dropdown.
I tried populating the dropdown in Load, PreRender and neither of them helped. I also did if not Postback which didn't help either.
Any ideas?
Here is the code Sample:
Thanks.
Asp.net - It only includes relevant code:
<%# Page Title="Register" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="Register.aspx.vb" Inherits="Events.Register" EnableEventValidation="false" Trace="true" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="../Scripts/CommonScripts.js">
</script>
<style type="text/css">
.textInput {
width: 150px;
}
.dropdownField
{
width: 155px;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="False"
Height="68px" Width="70%" >
<FinishNavigationTemplate>
<table cellpadding="5px" width="100%">
<tr>
<td align="center" width="50%">
<asp:Button ID="FinishButton" runat="server" CommandName="MoveComplete"
Text="Finish" onclick="RegisterUser_ActiveStepChanged" /></td>
</tr>
</table>
</FinishNavigationTemplate>
<LayoutTemplate>
<asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
<asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
<ContentTemplate>
<table style="font-size:100%;height:100%;width:100%;">
<tr>
<td align="center" colspan="2">
Sign Up for Your New Account</td>
</tr>
<tr>
<td align="right" style="width:40%">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmPasswordLabel" runat="server"
AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
ControlToValidate="ConfirmPassword"
ErrorMessage="Confirm Password is required."
ToolTip="Confirm Password is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
</td>
<td>
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server"
ControlToValidate="Email" ErrorMessage="E-mail is required."
ToolTip="E-mail is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security Question:</asp:Label>
</td>
<td>
<asp:TextBox ID="Question" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="QuestionRequired" runat="server"
ControlToValidate="Question" ErrorMessage="Security question is required."
ToolTip="Security question is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label>
</td>
<td>
<asp:TextBox ID="Answer" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server"
ControlToValidate="Answer" ErrorMessage="Security answer is required."
ToolTip="Security answer is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="PasswordCompare" runat="server"
ControlToCompare="Password" ControlToValidate="ConfirmPassword"
Display="Dynamic"
ErrorMessage="The Password and Confirmation Password must match."
ValidationGroup="RegisterUser"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
</ContentTemplate>
<CustomNavigationTemplate>
<table border="0" cellspacing="5" style="width:100%;height:100%;">
<tr align="right">
<td align="center" colspan="0">
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Create User" ValidationGroup="RegisterUser" />
</td>
</tr>
</table>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:WizardStep runat="server" Title="General Information" StepType="Finish"
ID="GeneralInfo">
<table style="font-size:100%; width:100%; height:100%">
<tr>
<td align="center" colspan="2">
Please Add Additional Account Information</td>
</tr>
<td align="right">
Birthday:
</td>
<td>
<asp:TextBox class="textInput" ID="Birthday" runat="server"></asp:TextBox>
<asp:ImageButton ID="BirthdayButton" runat="server" ImageUrl="~/Images/Calendar.png" Height="24" Width="24" ImageAlign="Baseline" />
<asp:CalendarExtender TargetControlID="Birthday" ID="BirthdayExtender" runat="server" PopupButtonID="BirthdayButton" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Birthday" ErrorMessage="Birthday is required."
ToolTip="Birthday is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
Religious Observance:
</td>
<td>
<asp:DropDownList class="dropdownField" ID="ReligiousObservance" runat="server"
DataSourceID="HashkafaDataSource" DataTextField="chvDescription"
DataValueField="intReligiousMasterID" AppendDataBoundItems="true" >
<asp:ListItem Value="0">Select One</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="HashkafaDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:EventsDB.06-ConnectionString %>"
SelectCommand="select s.chvSiteName, r.intReligiousMasterID, r.chvDescription from
tblSiteMaster as s inner join tblSiteReligious as sr on s.intSiteID=sr.intSiteID
inner join tblReligiousMaster as r on r.intReligiousMasterID=sr.intReligiousMasterID
where s.intSiteID=cast(#SiteID As int)">
<SelectParameters>
<asp:Parameter Name="SiteID"/>
</SelectParameters>
</asp:SqlDataSource>
<asp:RequiredFieldValidator ID="ReligiousObservanceRequired" runat="server"
ControlToValidate="ReligiousObservance" ErrorMessage="Religious Observance is required."
ToolTip="Religious Observance is required." ValidationGroup="RegisterUser">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
</table>
<%-- <CustomNavigationTemplate/> --%>
</asp:WizardStep>
<asp:CompleteWizardStep runat="server">
<ContentTemplate>
<table style="font-size:100%;height:68px;width:70%;">
<tr>
<td>
Your account has been successfully created.</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="ContinueButton" runat="server" CausesValidation="False"
CommandName="Continue" Text="Continue" ValidationGroup="RegisterUser" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
<StartNavigationTemplate>
hello<br />
</StartNavigationTemplate>
<StepNavigationTemplate>
<table cellpadding="5px" width="100%">
<tr>
<td align="right"><asp:Button ID="StepPreviousButton" runat="server" CausesValidation="False"
CommandName="MovePrevious" Text="Previous" /> </td>
<td align="left"> <asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Next" Height="20" Width="18" /> </td> </tr>
</table>
</StepNavigationTemplate>
</asp:CreateUserWizard>
</asp:Content>
VB.net code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If (Not IsPostBack) Then
' PopulateReligiousDropdown()
'End If
'Scripts for state and country drop down
' Commented out because doing in ASP.Net
' Page.ClientScript.RegisterStartupScript(Me.GetType(), _
' "MyScript", _
' "window.onload=init();" & _
' "function init() { " & _
' "fillList(document.getElementById('MainContent_RegisterUser_dropCountry'), areas[5]);" & _
' "fillList(document.getElementById('MainContent_RegisterUser_dropState'), areas[0]);" & _
'" }", True)
PhotoUploadValidator.ValidationExpression = HelperMethods.regexPhotos.ToString()
RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
' Populate ReligiousDropdown
HelperMethods.SiteID = HelperMethods.GetSiteID("Request.Url.Host")
HashkafaDataSource.SelectParameters.Item(0).DefaultValue = HelperMethods.SiteID
End Sub
Protected Sub RegisterUser_ActiveStepChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RegisterUser.ActiveStepChanged
' Have we JUST reached the Complete step?
If RegisterUser.ActiveStep.Title = "General Information" Then
'PopulateReligiousDropdown()
End If
If RegisterUser.ActiveStep.Title = "Complete" Then
Dim GeneralInfo As WizardStep = CType(RegisterUser.FindControl("GeneralInfo"), WizardStep)
' Programmatically reference the TextBox controls
Dim LastName As TextBox = CType(GeneralInfo.FindControl("LastName"), TextBox)
Dim FirstName As TextBox = CType(GeneralInfo.FindControl("FirstName"), TextBox)
Dim dropCountry As DropDownList = CType(GeneralInfo.FindControl("dropCountry"), DropDownList)
Dim dropState As DropDownList = CType(GeneralInfo.FindControl("dropState"), DropDownList)
Dim City As TextBox = CType(GeneralInfo.FindControl("City"), TextBox)
Dim ZipCode As TextBox = CType(GeneralInfo.FindControl("ZipCode"), TextBox)
Dim Address As TextBox = CType(GeneralInfo.FindControl("Address"), TextBox)
Dim Phone As TextBox = CType(GeneralInfo.FindControl("Phone"), TextBox)
Dim Birthday As TextBox = CType(GeneralInfo.FindControl("Birthday"), TextBox)
Dim ReligiousObservance As DropDownList = CType(GeneralInfo.FindControl("ReligiousObservance"), DropDownList)
' Dim PhotoUpload As TextBox = CType(GeneralInfo.FindControl("PhotoUpload"), TextBox)
' Update the UserProfiles record for this user
' Get the UserId of the just-added user
Dim newUser As MembershipUser = Membership.GetUser
Dim newUserId As Guid = CType(newUser.ProviderUserKey, Guid)
' Insert a new record into UserProfiles
Dim connectionString As String = ConfigurationManager.ConnectionStrings("EventsDB.06-ConnectionString").ConnectionString
Dim updateSql As String = "Insert into tblUsers " & _
"Values (#UserId, GETDATE(), #FirstName, #LastName, #dropCountry, #dropState, #City, #ZipCode, #Address, #Phone, #Birthday, #ReligiousObservance)"
Using myConnection As New SqlConnection(connectionString)
myConnection.Open()
Dim myCommand As New SqlCommand(updateSql, myConnection)
myCommand.Parameters.AddWithValue("#UserId", newUserId)
myCommand.Parameters.AddWithValue("#LastName", LastName.Text.Trim())
myCommand.Parameters.AddWithValue("#FirstName", FirstName.Text.Trim())
myCommand.Parameters.AddWithValue("#dropCountry", dropCountry.SelectedValue)
myCommand.Parameters.AddWithValue("#dropState", dropState.SelectedValue)
myCommand.Parameters.AddWithValue("#City", City.Text.Trim())
myCommand.Parameters.AddWithValue("#ZipCode", ZipCode.Text.Trim())
myCommand.Parameters.AddWithValue("#Address", Address.Text.Trim())
myCommand.Parameters.AddWithValue("#Phone", Phone.Text.Trim())
myCommand.Parameters.AddWithValue("#Birthday", Birthday.Text.Trim())
myCommand.Parameters.AddWithValue("#ReligiousObservance", ReligiousObservance.SelectedIndex)
'The dropdown's are not populating the server. The Value isn't being passed
' and I don't know why?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
myCommand.ExecuteNonQuery()
myConnection.Close()
End Using
End If
End Sub