Edit button not working on datalist causes invalid postback - asp.net

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

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.

For Loop or Dim for getting a handle on data from a Datagrid in a Checkbox

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.

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?

ItemUpdating NewValues Missing Parameter

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}") %>'

Resources