ItemUpdating NewValues Missing Parameter - asp.net

I have a formview with several data items that works perfectly except for a single parameter that will not update with the rest of them. The formview's datasource updateparameter is set to do nothing so that I can handle the update in codebehind. Every item works fine, except for one parameter ("salesprice") that is missing in the OldValues and NewValues argument of the ItemUpdating event of the formview. The data DOES pull in to the textbox as it should, formatted properly and all.
I've attached the html, SQL (for getLoanData()), and the codebehind.
Why would every parameter exist in the New/OldValue arguments except the "salesprice" parameter? I've tried populating the textbox without the formatstring, and it's still missing. Is there something about a money SQL datatype that might cause a problem?
HTML:
<asp:FormView ID="fvLoanDetails" runat="server" DataKeyNames="orderid"
DataSourceID="sqlLoanDetails" Width="100%">
<ItemTemplate>
...
</ItemTemplate>
<EditItemTemplate>
<table class="orderSectionHeader">
<tr>
<td style="padding-left:10px;">
<h2>Loan Details</h2>
</td>
<td style="text-align:right;">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />
<asp:Button ID="bvnSave" runat="server" Text="Save" CommandName="Update" />
</td>
</tr>
</table>
<table class="orderSection">
<tr>
<td class="orderHeader" style="vertical-align:top;">
Loan Number
</td>
<td>
<asp:Label ID="lblLoanNumber" CssClass="orderData" runat="server"
Text='<%# Bind("loannumber") %>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Business Channel
</td>
<td>
<asp:DropDownList ID="ddlBusinessChannel" runat="server"
DataSourceID="sqlBusinessChannels" DataTextField="BusinessChannel"
DataValueField="BusinessChannel" SelectedValue='<%# Bind("businesschannel") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="sqlBusinessChannels" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="SELECT DISTINCT [BusinessChannel] FROM [Loans] ORDER BY [BusinessChannel]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="orderHeader">
Loan Type
</td>
<td>
<asp:DropDownList ID="ddlLoanType" runat="server"
DataSourceID="sqlLoanType" DataTextField="LoanType"
DataValueField="LoanType" SelectedValue='<%# Bind("loantype") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="sqlLoanType" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="SELECT DISTINCT [LoanType] FROM [Loans] ORDER BY [LoanType]">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="orderHeader">
Purpose
</td>
<td>
<asp:DropDownList ID="ddlPurpose" runat="server"
SelectedValue='<%# Bind("purpose") %>'>
<asp:ListItem Text="Purchase" Value="False" />
<asp:ListItem Text="Refinance" Value="True" />
</asp:DropDownList>
</td>
</tr>
<tr id="trSalesPrice" runat="server">
<td class="orderHeader">
Sales Price
</td>
<td>
<asp:TextBox ID="txtSalesPrice" CssClass="orderData" runat="server" Width="100"
Text='<%# Bind("salesprice", "{0:F2}") %>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower
</td>
<td>
<table cellspacing="0">
<tr style="font-size:8pt;padding-bottom:0px;">
<td>First</td><td>Last</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtBFirst" CssClass="orderData" runat="server" Width="80"
Text='<%# Bind("firstname") %>' />
</td>
<td>
<asp:TextBox ID="txtBLast" CssClass="orderData" runat="server" Width="120"
Text='<%# Bind("lastname") %>' />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Email
</td>
<td>
<asp:TextBox ID="txtEmail" CssClass="orderData" runat="server" Width="200"
Text='<%# Bind("email") %>' />
</td>
</tr>
<tr>
<td class="orderHeader" style="vertical-align:top;">
Mailing Address
</td>
<td>
<table cellspacing="0">
<tr style="font-size:8pt;padding-bottom:0px;">
<td colspan="3">Address</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox ID="txtAddress" CssClass="orderData" runat="server" Width="200"
Text='<%# Bind("address") %>' />
</td>
</tr>
<tr style="font-size:8pt;padding-bottom:0px;">
<td>City</td><td>State</td><td>Zip</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtCity" CssClass="orderData" runat="server" Width="100"
Text='<%# Bind("city") %>' />
</td>
<td>
<asp:TextBox ID="txtState" CssClass="orderData" runat="server" Width="30"
Text='<%# Bind("state") %>' />
</td>
<td>
<asp:TextBox ID="txtZip" CssClass="orderData" runat="server" Width="50"
Text='<%# Bind("zip") %>' />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Primary
</td>
<td>
<asp:TextBox ID="txtBPhone" CssClass="orderData" runat="server"
Text='<%# Bind("phone1", "{0:(###) ###-####}")%>' />
</td>
</tr>
<tr>
<td class="orderHeader">
Borrower Secondary
</td>
<td>
<asp:TextBox ID="txtBCell" CssClass="orderData" runat="server"
Text='<%# Bind("phone2", "{0:(###) ###-####}")%>' />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="sqlLoanDetails" runat="server"
ConnectionString="<%$ ConnectionStrings:Jade_4 %>"
SelectCommand="select #orderid as orderid, * from dbo.getLoanData(#orderid)"
UpdateCommand="select #orderid">
<SelectParameters>
<asp:ControlParameter ControlID="hdnOrderID" Name="orderid"
PropertyName="Value" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
VB.NET:
Protected Sub fvLoanDetails_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles fvLoanDetails.ItemUpdating
Dim o As Order = DAL.GetOrderById(hdnOrderID.Value)
Dim l As Loan = DAL.GetLoanByLoanID(o.LoanID)
Dim b As Contact = DAL.GetContactById(l.BorrowerContactID)
l.BusinessChannel = e.NewValues("businesschannel")
l.LoanType = e.NewValues("loantype")
l.Purpose = e.NewValues("purpose")
l.SalesPrice = e.NewValues("salesprice")
DAL.UpdateLoan(l)
b.FirstName = e.NewValues("firstname")
b.LastName = e.NewValues("lastname")
b.Address = e.NewValues("address")
b.City = e.NewValues("city")
b.State = e.NewValues("state")
b.Zip = e.NewValues("zip")
b.Phone = e.NewValues("phone1")
b.Cell = e.NewValues("phone2")
DAL.UpdateContact(b)
End Sub
SQL:
select
l.loannumber, l.businesschannel, l.loantype, l.purpose, l.salesprice, b.firstname, b.lastname, b.email,
b.address, b.city, b.state, b.zip, b.phone as phone1, b.cell as phone2,
dbo.formataddressweb(b.address, '', b.city, b.state, b.zip) as mailingaddress from loans l
join orders o on o.orderid=#orderid
join contacts b on l.borrowercontactid=b.contactid
where l.loanid=(select loanid from orders where orderid=#orderid)

Have you tried a different format string?
Text='<%# Bind("salesprice", "{0:C}") %>'

Related

Showing same table to different roles with different options

Currently I just post the same code in different pages for each role, a repeater with a table like this one but each role has different options to do. I tried to place in loginview separator but didn't work, i don't know how to iterate through login view controls and the code just started getting dirtier more than just doing visible = false / true. Is there a more effective way to do this than just making new pages?
<asp:Repeater ID="rptArtigos" runat="server" OnItemCommand="rptArtigos_OnItemCommand" OnItemDataBound="rptArtigos_OnItemDataBound">
<HeaderTemplate>
<table id="tblArtigos" class="table table-bordered dataTable text-center">
<thead class="thead-dark">
<tr>
<th>ID</th>
<th>Ref. Cliente</th>
<th>Ref. Interna</th>
<th>Nome</th>
<th>Estado</th>
<th>Válido Logística</th>
<th>Data Criação</th>
<th></th>
<th></th>
<th id="cell1" runat="server"></th>
<th></th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr>
<td>
<asp:Label ID="lblIdArtigo" runat="server" Text='<%# Eval("IdArtigo") %>' />
</td>
<td>
<asp:Label ID="lblRefCliente" runat="server" Text='<%# Eval("ReferenciaCliente") %>' />
</td>
<td>
<asp:Label ID="lblRefInterna" runat="server" Text='<%# Eval("ReferenciaInterna") %>' />
</td>
<td>
<asp:LinkButton ID="lkbtnNome" runat="server" Text='<%# Eval("Nome") %>' CommandName="Ver" CommandArgument='<%# Eval("IdArtigo") %>'></asp:LinkButton>
</td>
<td>
<asp:Label ID="lblEstado" runat="server" Text='<%# Eval("EstadoArtigo") %>' />
</td>
<td>
<asp:Label ID="lblAprovadoLogistica" runat="server" Text='<%# Eval("AprovadoLogistica") %>' />
</td>
<td>
<asp:Label ID="lblDataCriacao" runat="server" Text='<%# Eval("DataCriacao") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Icones/copy.png" Width="25" runat="server" CommandName="Copiar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/edit.png" Width="25" runat="server" CommandName="Editar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/success.png" Width="25" runat="server" OnClientClick="return false;" data-toggle="modal" data-target="#validate" CommandName="Validar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
<td class="text-center">
<asp:ImageButton ImageUrl="/Images/Buttons/x-button.png" Width="25" runat="server" CommandName="Rejeitar" CommandArgument='<%# Eval("IdArtigo") %>' />
</td>
</tr>
</tbody>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

ASP.Net Formview skipping records when paging

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.

Edit button not working on datalist causes invalid postback

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

update data In Repeater Control Using Button Outside It

I am having 5 div tags,in each div tag I am having repeater control.I want to allow user update information if he want.So on form load,I am retrieving all information from table,so one can update information.But I am unable to do this.I am giving the code for 3 repeater control.I tried this on button update click.Problem is when i clicked on update button it is not loop through first 4 repeater's for each loop,it just loop through the last for each loop.And I have created store procedure to update information.So,I want to send all parameters to it like:
enter code here
ob.UpdateProfile(profileid, candiid, pheadline, ethnicity, religion, caste, starsign, purpose, maritalstatus, lang, htid, height, wt, skincolor, eyesight, abtme, diet, drink, smoking, drug, frndship, schoolname, schpassyr, collegename, collgpassyr, compwebsite);
enter code here
foreach (RepeaterItem repItem in repProfileInfo.Items)
{
TextBox tProfileHeadline = repItem.FindControl("txtProfileHeadline") as TextBox;
pheadline = tProfileHeadline.Text;
DropDownList ddlEthnicity = repItem.FindControl("drpEthnicity") as DropDownList;
ethnicity = ddlEthnicity.SelectedItem.Text;
DropDownList ddlReligion = repItem.FindControl("drpReligion") as DropDownList;
religion = ddlReligion.SelectedItem.Text;
TextBox tCaste = repItem.FindControl("txtCaste") as TextBox;
caste = tCaste.Text;
DropDownList ddlStarSign = repItem.FindControl("drpStarSign") as DropDownList;
starsign = ddlStarSign.SelectedItem.Text;
DropDownList ddlPurpose = repItem.FindControl("drpPurpose") as DropDownList;
purpose = ddlPurpose.SelectedItem.Text;
DropDownList ddlMaritalStatus = repItem.FindControl("drpMaritalStatus") as DropDownList;
maritalstatus = ddlMaritalStatus.SelectedItem.Text;
TextBox tLanguage = repItem.FindControl("txtLanguage") as TextBox;
lang = tLanguage.Text;
TextBox tSchoolName = repItem.FindControl("txtSchoolName") as TextBox;
schoolname = tSchoolName.Text;
DropDownList ddlSchoolPassYr = repItem.FindControl("drpSchoolPassYr") as DropDownList;
schpassyr = ddlSchoolPassYr.SelectedItem.Text;
TextBox tCollegeName = repItem.FindControl("txtCollegeName") as TextBox;
collegename = tCollegeName.Text;
DropDownList ddlCollegePassYr = repItem.FindControl("drpCollegePassYr") as DropDownList;
collgpassyr = ddlCollegePassYr.SelectedItem.Text;
TextBox tCompanyWebsite = repItem.FindControl("txtCompanyWebsite") as TextBox;
compwebsite = tCompanyWebsite.Text;
}
foreach(RepeaterItem repItem1 in repPhysicalInfo.Items)
{
DropDownList ddlHeight = repItem1.FindControl("drpHeight") as DropDownList;
htid =ddlHeight.SelectedValue;
height = ddlHeight.SelectedItem.Text;
TextBox tWeight = repItem1.FindControl("txtWeight") as TextBox;
wt = tWeight.Text;
DropDownList ddlSkinColor = repItem1.FindControl("drpSkinColor") as DropDownList;
skincolor = ddlSkinColor.SelectedItem.Text;
DropDownList ddlEyeSight = repItem1.FindControl("drpEyeSight") as DropDownList;
eyesight = ddlEyeSight.SelectedItem.Text;
}
foreach(RepeaterItem repItem2 in repAbootMe.Items)
{
TextBox tAboutMe = repItem2.FindControl("txtAboutMe") as TextBox;
abtme = tAboutMe.Text;
CheckBox chkFriendShip = repItem2.FindControl("chkActivateFriendship") as CheckBox;
if (chkFriendShip.Checked == true)
frndship = "Yes";
else
frndship = "No";
}
As it is loop through the last for each loop,I am getting error in procedure,as it is not getting all its parameter.Variables I defined in first 4 repeater control loop,getting null value.So I want know how I can get information in all repeater controls,so i can update it.Give me any solution for this.Thanks in advance.
Design code of web form:
Height:
' Width="150px">
4.10
4.11
5.0
5.1
5.2
5.3
5.4
5.5
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Weight
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtWeight" runat="server" Text='<%#Eval("wt") %>' Width="150px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Skin Color:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtSkinColor" runat="server" Text='<%#Eval("skincolor")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpSkinColor" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem>Wheatish</asp:ListItem>
<asp:ListItem>Fair</asp:ListItem>
<asp:ListItem>Tan/Brown</asp:ListItem>
<asp:ListItem>Dark</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Eye Sight:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtEyeSight" runat="server" Text='<%#Eval("eyesight")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpEyeSight" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem>Clear</asp:ListItem>
<asp:ListItem>Glasses</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
</div>
<div id="aboutMe" runat="server" visible="false" style="margin-left: 50px; display: block">
<asp:Repeater ID="repAbootMe" runat="server" OnItemDataBound="myAboutMe">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="directorytdWidth">
About Me:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtAboutMe" runat="server" Text='<%#Eval("aboutMe")%>' Width="200px"
TextMode="MultiLine" Height="100px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Active Friendship Zone:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtActiveFrndZone" runat="server" Text='<%#Eval("friendship")%>'
Width="100px"></asp:TextBox>
<asp:CheckBox ID="chkActivateFriendship" runat="server" Text="Activate My Friendship Zone Profile"
Checked="True" ForeColor="#000000" Visible="false" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
<div id="otherInfo" runat="server" visible="false" style="margin-left: 50px; display: block">
<asp:Repeater ID="repOtherInfo" runat="server" OnItemDataBound="myOtherInfo">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="directorytdWidth">
Diet:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDiet" runat="server" Text='<%#Eval("diet")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpDiet" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Veg</asp:ListItem>
<asp:ListItem>Non-Veg</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Drink:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDrink" runat="server" Text='<%#Eval("drink")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpDrinks" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Don't Drink</asp:ListItem>
<asp:ListItem>Drink Socially</asp:ListItem>
<asp:ListItem>Drink like fish</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Smoke:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtSmoke" runat="server" Text='<%#Eval("smoke")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpSmoking" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Don't Smoke</asp:ListItem>
<asp:ListItem>Smoke Socially</asp:ListItem>
<asp:ListItem>Smoker</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Drugs:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDrug" runat="server" Text='<%#Eval("drug")%>' Width="150px"></asp:TextBox>
<asp:DropDownList ID="drpDrug" runat="server" Height="24px" Width="100px" Visible="false">
<asp:ListItem></asp:ListItem>
<asp:ListItem>No Drugs</asp:ListItem>
<asp:ListItem>Druggi</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
</div>
<div id="contactInfo" runat="server" visible="false" style="margin-left: 50px; display: block">
<asp:Repeater ID="repContactInfo" runat="server" OnItemDataBound="myContactInfo">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="directorytdWidth">
First Name:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtFirstName" runat="server" Width="150px" Text='<%#Eval("firstName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Last Name:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtLastName" runat="server" Width="150px" Text='<%#Eval("lastName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Gender:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtGender" runat="server" Width="100px" Text='<%#Eval("gender")%>'></asp:TextBox>
<asp:RadioButtonList ID="radioGender" runat="server" RepeatColumns="2" Visible="false">
<asp:ListItem Text="Male" Value="M"></asp:ListItem>
<asp:ListItem Text="Female" Value="F"> </asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Address:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtAdd" runat="server" Width="200px" Text='<%#Eval("candiAddress")%>'
TextMode="MultiLine" Height="75px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Country:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtCountry" runat="server" Width="150px" Text='<%#Eval("countryName")%>'></asp:TextBox>
<asp:DropDownList ID="drpCountry" runat="server" Width="150px" Height="24px" Visible="false"
AutoPostBack="true" OnSelectedIndexChanged="drpCountry_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
State:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtState" runat="server" Width="150px" Text='<%#Eval("stateName")%>'></asp:TextBox>
<asp:DropDownList ID="drpState" runat="server" Width="150px" Visible="false" Height="24px"
AutoPostBack="true" OnSelectedIndexChanged="drpState_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
City:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtCity" runat="server" Width="150px" Text='<%#Eval("cityName")%>'></asp:TextBox>
<asp:DropDownList ID="drpCity" runat="server" Width="150px" Height="24px" Visible="false"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Postal Code:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtPostalCode" runat="server" Width="150px" Text='<%#Eval("pincode")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Landline:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtLandline" runat="server" Width="150px" Text='<%#Eval("landline")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Mobile Number:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtMobile" runat="server" Width="150px" Text='<%#Eval("mobile")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Date of Birth:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtDob" runat="server" Width="150px" Text='<%#Eval("dob")%>'></asp:TextBox>
<asp:DropDownList ID="drpYear" runat="server" Visible="false" Height="24px" Width="80px"
AutoPostBack="true">
</asp:DropDownList>
<asp:DropDownList ID="drpMonth" runat="server" Height="24px" Width="80px" OnSelectedIndexChanged="drpMonth_SelectedIndexChanged"
AutoPostBack="true" Visible="false">
<asp:ListItem Value="1" Selected="True">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="drpDate" runat="server" Height="24px" Width="50px" Visible="false"
AutoPostBack="true">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="directorytdWidth">
Email Address:
</td>
<td class="directoryTdPadding">
<asp:TextBox ID="txtEmail" runat="server" Width="150px" Text='<%#Eval("altEmail")%>'></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
</div>
<div style="text-align: center">
<asp:Button ID="btnUpdate" Text="Update" runat="server" CssClass="btnImage" OnClick="btnUpdate_Click" /></div>
</div>

asp.net listview and findcontrol

I have listview and i need to bind the dropdown list in the list view to ListItemCollection which will be built using a function BindPages().
When I clicked on the AddNew Link I am not able to bind the dropdown.
<asp:ListView DataKeyNames="Menuid" OnItemCommand="lvParentMenus_ItemCommand" OnSorting="lvParentMenus_Sorting"
OnDataBound="lvParentMenus_DataBound" DataSourceID="SqlDataSource1" ID="lvParentMenus"
runat="server">
<LayoutTemplate>
<table border="0" id="listview" width="100%" class="grid" cellpadding="0" cellspacing="0">
<thead>
<tr class="listingheader ">
<td width="10%" style="text-align: center; !important">
<input type="checkbox" name="checkbox" id="headercheck" />
</td>
<td id="thsno" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="Sno"
Text="Sno" />
</td>
<td id="thmenutext" runat="server">
<asp:LinkButton runat="server" ID="LinkButton2" Text="Menu Text" CommandName="Sort"
CommandArgument="MenuText" />
</td>
<td id="thmenuurl" runat="server">
<asp:LinkButton runat="server" ID="LinkButton3" Text="Menu Url" CommandName="Sort"
CommandArgument="MenuUrl" />
</td>
<td id="thlevel" runat="server">
<asp:LinkButton runat="server" ID="LinkButton4" Text="Level of Display" CommandName="Sort"
CommandArgument="level" />
</td>
<td>
Action
</td>
</tr>
</thead>
<tbody>
<tr runat="server" id="itemPlaceholder">
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3" align="center">
<asp:Label ID="lblMessage" Text="dfdfdfd" runat="server"></asp:Label>
</td>
<td align="right">
<asp:LinkButton Text="Add New" ID="lnkNew" CommandName="FillDropDown" runat="server"
Font-Bold="true" OnClick="AddNew"></asp:LinkButton>
</td>
</tr>
</tfoot>
</table>
<ItemTemplate>
<tr class='<%# Container.DataItemIndex % 2 == 0 ? "lrow1" : "lrow1 altrow" %>'>
<td class="col1" align="center">
<asp:CheckBox runat="server" ID="chkitem"></asp:CheckBox>
</td>
<td class="lrow1">
<%# Eval("Sno")%>
<asp:HiddenField ID="hdnStoreID" runat="server" Value='<%# Eval("MenuId") %>' />
</td>
<td>
<%# Eval("MenuText")%>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSource='<%#BindLevel(6)%>' SelectedValue='<%# Eval("level")%>'>
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit">Edit</asp:LinkButton>
|
<asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" OnClientClick="javascript:return confirm('Are you sure to delete the current item');">Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr class="lrow1">
<td class="col1" align="center">
</td>
<td class="lrow1">
</td>
<td class="lrow1">
<asp:TextBox ID="txtMenuText" runat="server" Width="80px" Text='<%# Eval("MenuText")%>'
CssClass="inputbox" ValidationGroup="InsertFields" />
<asp:RequiredFieldValidator ID="reqValidCity" ControlToValidate="txtMenuText" runat="server"
ErrorMessage="City Name is required." Display="Dynamic" ValidationGroup="InsertFields">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regValidCity" runat="server" ErrorMessage="Please Enter Alphabets only."
Display="Dynamic" ValidationGroup="g1" ControlToValidate="txtMenuText" ValidationExpression="^[a-zA-Z0-9\s]{2,1000}"></asp:RegularExpressionValidator>
</td>
<td>
<asp:DropDownList ID="ddlPagesList" runat="server" DataSource='<%#BindPages()%>'>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlLevel" runat="server" DataSourceID="sdsLevel" DataValueField="level"
DataTextField="level">
</asp:DropDownList>
</td>
<td nowrap="nowrap">
<asp:LinkButton ID="lnkinsert" runat="server" OnClick="lnkinsert_Click" ValidationGroup="InsertFields"> Insert</asp:LinkButton>
</td>
</tr>
</InsertItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="usp_getParentMenus"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="ddlRoles" Name="intRoleid" PropertyName="Text" DefaultValue="1"
ConvertEmptyStringToNull="true" Direction="Input" />
</SelectParameters>
</asp:SqlDataSource>
and here is the method BindPAges()
protected ListItemCollection BindPages()
{
string sDir = Request.PhysicalApplicationPath;
if (FirstCount == 0)
DirSearch(sDir);
return collection;
}
When I tried to find the ddlPageList in the AddNew() method it is throwing error "Object referenc not set "
AddNEw() Method:
` protected void AddNew(object sender, EventArgs e)
{
lvParentMenus.InsertItemPosition = InsertItemPosition.FirstItem;
lvParentMenus.FindControl("lnkNew").Visible = false;
lvParentMenus.EditIndex = -1;
sdsLevel.ConnectionString = DBConnectionString.ConnectionString;
Parameter a = new Parameter("intRoleid", DbType.Int32);
a.DefaultValue = ddlRoles.SelectedValue.ToString();
sdsLevel.SelectParameters.Add(a);
sdsLevel.SelectCommand = "usp_getParentMenus";
DropDownList ddlpages = (DropDownList)lvParentMenus.FindControl("ddlPagesList");
string sDir = Request.PhysicalApplicationPath;
DirSearch(sDir);
ddlpages.DataSource = collection;
ddlpages.DataBind();
}
Need urgently.
Thanks.
Please try
DropDownList ddlpages = (DropDownList)lvParentMenus.Items[0].FindControl("ddlPagesList");
Have you tried to use runat=server property in TABLE in Listview?

Resources