Hi I am trying to implement a nested user control in listview and the user control doesn't get bound.
Here is my code.
<asp:ListView ID="ListViewTaskList" runat="server" DataKeyNames="TaskID"
DataSourceID="SqlDataSourceTaskList" OnItemDataBound="ListViewTaskListItemDataBound" ItemPlaceholderID="itemPlaceholder">
<LayoutTemplate>
<div class="ListView ">
<div style="font-size:2em;color:#555555;margin-bottom:20px;">Task List</div>
<div ID="itemPlaceholder" runat="server">
</div>
</div>
</LayoutTemplate>
<ItemTemplate>
<div class="rlvI">
<asp:Label ID="TaskIDLabel" runat="server" Text='<%# Eval("TaskID") %>' />
<asp:Label ID="TaskLabel" runat="server" Text='<%# Eval("Task") %>' />
<asp:Label ID="CreatedDateLabel" runat="server" Text='<%# Eval("CreatedDate") %>' />
<asp:Label ID="UpdatedDateLabel" runat="server" Text='<%# Eval("UpdatedDate") %>' />
<asp:Label ID="TimestampLabel" runat="server" Text='<%# Eval("Timestamp") %>' />
<asp:Label ID="TaskTypeIDLabel" runat="server" Text='<%# Eval("TaskTypeID") %>' />
<asp:Label ID="ProjectTaskStatusIDLabel" runat="server" Text='<%# Eval("ProjectTaskStatusID") %>' />
<asp:Label ID="SystemObjectIDLabel" runat="server" Text='<%# Eval("SystemObjectID") %>' />
<asp:Label ID="SystemObjectRecordIDLabel" runat="server" Text='<%# Eval("SystemObjectRecordID") %>' />
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='<%# Eval("Active") %>' Enabled="false" />
<asp:Label ID="CreatedByAccountIDLabel" runat="server" Text='<%# Eval("CreatedByAccountID") %>' />
<asp:Label ID="UpdatedByAccountIDLabel" runat="server" Text='<%# Eval("UpdatedByAccountID") %>' />
<asp:Button ID="SelectButton" runat="server" CausesValidation="False" CommandName="Select" CssClass="rlvBSel" Text=" " ToolTip="Select" />
<div>
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' systemObjectRecordID="Comments1Init" />
</div>
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div class="rlvA">
<asp:Label ID="TaskIDLabel" runat="server" Text='<%# Eval("TaskID") %>' />
<asp:Label ID="TaskLabel" runat="server" Text='<%# Eval("Task") %>' />
<asp:Label ID="CreatedDateLabel" runat="server"
Text='<%# Eval("CreatedDate") %>' />
<asp:Label ID="UpdatedDateLabel" runat="server"
Text='<%# Eval("UpdatedDate") %>' />
<asp:Label ID="TimestampLabel" runat="server"
Text='<%# Eval("Timestamp") %>' />
<asp:Label ID="TaskTypeIDLabel" runat="server"
Text='<%# Eval("TaskTypeID") %>' />
<asp:Label ID="ProjectTaskStatusIDLabel" runat="server"
Text='<%# Eval("ProjectTaskStatusID") %>' />
<asp:Label ID="SystemObjectIDLabel" runat="server"
Text='<%# Eval("SystemObjectID") %>' />
<asp:Label ID="SystemObjectRecordIDLabel" runat="server"
Text='<%# Eval("SystemObjectRecordID") %>' />
<asp:CheckBox ID="ActiveCheckBox" runat="server"
Checked='<%# Eval("Active") %>' Enabled="false" />
<asp:Label ID="CreatedByAccountIDLabel" runat="server"
Text='<%# Eval("CreatedByAccountID") %>' />
<asp:Label ID="UpdatedByAccountIDLabel" runat="server"
Text='<%# Eval("UpdatedByAccountID") %>' />
<asp:Button ID="SelectButton" runat="server" CausesValidation="False"
CommandName="Select" CssClass="rlvBSel" Text=" " ToolTip="Select" />
<div>
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' '<%# Eval("TaskID") %>' />
</div>
</div>
</AlternatingItemTemplate>
``
I have been struggling with this problem for a few days now.
Please help!!
Please help!
if I look at your code, it seems to me that you aren't actually assigning the binding to anything:
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' '<%# Eval("TaskID") %>' />
try instead
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' YourProperty='<%# Eval("TaskID") %>' />
EDIT: in order to achieve two way data binding, one has to add BindableAttribute to the property on User Control
Related
please excuse this potentially long post as I feel like most of the information I will add below is necessary. As the title states I am trying to loop through a collection of controls that are within a gridview on my page (there are 2 gridviews actually, but they are identical in behavior) and store the values of some of these controls in an array that I can use to perform other functions.
To start I have added the code for the gridview below.
<asp:Panel ID="gridPNL1" runat="server">
Repair / Labor<asp:LinkButton runat="server" ID="lbAddRepair" Text="Add New Repair / Labor" CommandName="AddLabor" OnClick="AddObject_Click" Enabled="false" style="margin-left:20px" Visible="false" />
<asp:GridView ID="GridView1" runat="server"
EmptyDataText="No Claimed Labor" AutoGenerateColumns="False"
ShowHeaderWhenEmpty="True" DataKeyNames="RecID"
ShowFooter="True" DataSourceID="SqlDataSource6" Width="95%">
<RowStyle HorizontalAlign="Center" />
<EmptyDataTemplate>
<asp:DropDownList ID="ddlRepairEquipmentNew" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID"
DataTextField="EquipmentPart" AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px"
Style="margin-left: 70px;" > <%-- Removed the OnSelectedIndexChanged (add if needed) --%>
<asp:ListItem Value ="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairNew" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID"
DataTextField="Description" AppendDataBoundItems="True" Width="220px" Height="20px" AutoPostBack="true"
style="" OnSelectedIndexChanged="ddlRepairNew_SelectedIndexChanged"
OnDataBinding="ddlRepairNew_DataBinding">
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<%-- <asp:textbox ID="txtDescOther" runat="server" Width="235px" Visible="false" />--%>
<asp:textbox runat="server" ID="txtRepairHoursNew" Width="95px" style="margin-left: 68px"/>
<%--<asp:Label runat="server" ID="lblRepairHoursAllowed"></asp:Label>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursNew" />
<%-- <asp:textbox ID="txtAllowedHoursNew" runat="server" Width="90px"/>--%>
<asp:textbox ID="txtRepairCostNew" runat="server" Width="95px" ReadOnly="True"/>
<asp:textbox ID="txtLineTotalNew" runat="server" Width="95px" ReadOnly="true"/>
<asp:textbox ID="txtTaxNew" runat="server" Width="95px" text="0"/>
<asp:Button ID="InsertDetail" runat="server" CommandName="InsertDetail" Height="25px" Text="Add Detail" Width="85px" />
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowEditButton="True" footertext="Add -->" ShowDeleteButton="True" HeaderStyle-Width="70px"/>
<asp:BoundField DataField="RecID" HeaderText="RecID" SortExpression="RecID" ReadOnly="True" Visible="False" />
<asp:TemplateField HeaderText="Equipment / Repair / Labor Description" ItemStyle-HorizontalAlign="center" >
<ItemTemplate>
<asp:Label ID="lblRepairEquipmentType" Text='<%# Bind("EquipmentType") %>' runat="server" Enabled="False" Width="220px" />
<asp:label ID="lblRepairType" Text='<%# Bind("RepairType") %>' runat="server" Enabled="False" Width="220px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlRepairEquipmentEdit" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID" DataTextField="EquipmentPart" SelectedValue='<%# Eval("EquipmentID") %>' AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px" >
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairEdit" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID" DataTextField="Description" SelectedValue='<%# Eval("RepairID")%>' AppendDataBoundItems="True" AutoPostBack="true" Width="220px" Height="20px" OnSelectedIndexChanged="ddlRepairEdit_SelectedIndexChanged" />
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlRepairEquipmentInsert" runat="server" DataSourceID="SqlDataSourcePartEquipment" DataValueField="RecID" DataTextField="EquipmentPart" AppendDataBoundItems="True" AutoPostBack="True" Width="220px" Height="20px" Style="margin-left: 29px" >
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlRepairInsert" runat="server" DataSourceID="SqlDataSourceRepair" DataValueField="RecID" DataTextField="Description" AppendDataBoundItems="True" autopostback="true" Width="220px" Height="20px" OnSelectedIndexChanged="ddlRepairInsert_SelectedIndexChanged" OnDataBinding="ddlRepairInsert_DataBinding">
<asp:ListItem Value="0">---SELECT---</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Repair Hours Requested" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairHours" Text='<%# Bind("RepairHours")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairHoursEdit" Text='<%# Bind("RepairHours")%>' runat="server" Width="95px" />
<%--<asp:Label ID="lblRepairHoursEdit" runat="server"></asp:Label>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursEdit" Value='<%# Bind("AllowedHours")%>' />
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairHoursInsert" runat="server" style="width: 100%; box-sizing: border-box;"/>
<%--<center><asp:Label ID="lblRepairHoursInsert" runat="server"></asp:Label></center>--%>
<asp:HiddenField runat="server" ID="hidAllowedRepairHoursInsert" />
</FooterTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Repair Hours Approved" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblAllowedHours" Text='<%# Bind("AllowedHours")%>' runat="server" Width="50px"/>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtAllowedHoursEdit" Text='<%# Bind("AllowedHours")%>' Enabled="true" runat="server" Width="50px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtAllowedHoursInsert" Text='<%# Bind("AllowedHours")%>' runat="server" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Repair Cost" ItemStyle-HorizontalAlign="center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairCost" Text='<%# Bind("RepairCost", "{0:C}") %>' runat="server" Enabled="False"/>
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairCostEdit" Text='<%# Bind("RepairCost") %>' runat="server" ReadOnly="True" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairCostInsert" Text='<%# Bind("RepairCost") %>' runat="server" ReadOnly="True" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Repair Total" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:label ID="lblRepairTotal" Text='<%# Bind("LaborRequested", "{0:C}")%>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="txtRepairTotalEdit" Text='<%# Bind("LaborRequested")%>' Enabled="false" runat="server" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtRepairTotalInsert" Text='<%# Bind("LaborRequested") %>' runat="server" Enabled="false" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tax" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="100px">
<ItemTemplate>
<asp:LinkButton ID="lbTaxTotal" Text='<%# Bind("Tax", "{0:C}")%>' runat="server" CommandArgument="Repair" OnClick="lblTaxTotal_Click" />
<asp:HiddenField ID="hidRepairGST" runat="server" Value='<%# Bind("GST")%>' />
<asp:HiddenField ID="hidRepairPST" runat="server" Value='<%# Bind("PST")%>' />
<asp:HiddenField ID="hidRepairQST" runat="server" Value='<%# Bind("QST")%>' />
<asp:HiddenField ID="hidRepairHST" runat="server" Value='<%# Bind("HST")%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:textbox ID="lblTaxTotalEdit" Text='<%# Bind("Tax")%>' Enabled="true" runat="server" Width="95px"/>
</EditItemTemplate>
<FooterTemplate>
<asp:textbox ID="txtTaxTotalInsert" runat="server" Enabled="true" text="0" style="width: 100%; box-sizing: border-box;"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Insert New" HeaderStyle-Width="85px">
<ItemTemplate>
<asp:Label ID="lblEmpty" Text="" runat="server" Width="85px"/>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Insert" runat="server" CommandName="InsertNewDetail" Height="22px" Text="Insert" style="width: 100%; box-sizing: border-box;" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#336699" ForeColor="White" />
</asp:GridView>
<asp:Label runat="server" ID="lblErrorRepair" ForeColor="Red" />
<br />
</asp:Panel>
What I am trying to do with the gridview above is loop through some specific controls on the gridview and store their values in an array. Essentially how this gridview works is the user will enter information into a series of drop down lists and textboxes, as seen above, when the user hits the button at the end of the row (labeled "InsertDetail" and "Insert" respectively, it takes the data from the drop down list and textboxes and stores it in the labels (also above) for simpler display (this goes on for however many items the user needs to enter (usually around 2 - 5 items total)). I need a way to loop through the values in however many iterations of "lblRepairEquipmentType" there are at the time the user hits any of the "insert" buttons and store the value of each iteration of "lblRepairEquipmentType" in an array so that I can use that array to perform other procedures.
Any help would be greatly appreciated and if there is something else I can try that would be better, either efficiency wise or just for best practices I would appreciate and welcome any constructive criticism. Thank you all for your patience and willingness to help.
I have a Page Fruit that has a UpdatePanel P1 and a ModalWIndow (outside of the updatepanel). I have a Page Apple with An UpdatePanel P2. ModalWindow on Page fruit will add Page Apple on demand.
Now, In the Apple Page
I have a GridView with EditItemTemplate and FooterItemtemplate for lets say 5 columns. Both of them have RegularExpressionValidator and RequiredFieldValidtor each separated by ValidationGroup. For EditItemTemplate everything is on point.
For FooterItemTemplate, the button won't do postback even though all the validation is met.
The footer template looks like this for the column of interest
<FooterTemplate>
<asp:TextBox ID="vendorAdd" runat="server" Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator66" ControlToValidate="vendorAdd" ValidationGroup="AddValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
<asp:RequiredFieldValidator id = "RegularExpressionValidator67" ValidationGroup="AddValidation" ControlToValidate="vendorAdd"
runat="server" ErrorMessage="VendorName Required" />
</FooterTemplate>
There is no message saying this failed. I removed the all the other validation on other footer column than shown above. I added on the button to stop validation. And in Server side added this
Page.Validate("AddValidation");
var b = Page.IsValid;
var notValidValidators = Page.Validators.Cast<IValidator>().Where(v => !v.IsValid);`
Here in the debugger the notValidValidator says that RequiredFieldValidator is not Valid. I don't see why though, I have a value and there is no message on the front end.
Update Panel on Apple Page full Code is below
<asp:UpdatePanel ID="ackPanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="ackedItems" runat="server" Width="720" Visible="true" DataKeyNames="AckId" RowStyle-Height="10px"
AutoGenerateColumns="False" BorderStyle="Dotted" BorderWidth="1px" CellPadding="2"
BackColor="White" BorderColor="#CCCCCC" HorizontalAlign="Left" AllowPaging="false"
ShowFooter="true" OnRowUpdating="AckedItems_RowUpdating" OnRowDeleting="AckedItems_RowDeleting"
OnRowEditing="AckedItems_RowEditing" OnRowCommand="AckedItems_RowCommand" OnRowDataBound="AckedItems_RowDataBound">
<RowStyle ForeColor="#000066" Font-Size="8pt" />
<HeaderStyle ForeColor="#336699" Font-Size="8pt" CssClass="GridViewHeader" Height="20px" />
<AlternatingRowStyle CssClass="GridViewAltStyle" />
<Columns >
<asp:BoundField DataField="AckId" ReadOnly="true" Visible="false" />
<asp:TemplateField HeaderText="Vendor" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="vendor" runat="server" Text='<%# Bind("VendorName") %>' Width="95%"/>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="vendorEdit" runat="server" Text='<%# Bind("VendorName") %>' Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="vendorEdit" ValidationGroup="EditValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
<asp:RequiredFieldValidator id = "Ab" ValidationGroup="EditValidation" ControlToValidate="vendorEdit"
runat="server" ErrorMessage="VendorName Required" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="vendorAdd" runat="server" Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator66" ControlToValidate="vendorAdd" ValidationGroup="AddValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid VendorName" />
<asp:RequiredFieldValidator id = "RegularExpressionValidator67" ValidationGroup="AddValidation" ControlToValidate="vendorAdd"
runat="server" ErrorMessage="VendorName Required" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount" HeaderStyle-Width="10px">
<ItemTemplate>
<asp:Label ID="amount" DataFormatString = "{0:C2}" runat="server" Text='<%# Bind("Amount") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="amountEdit" runat="server" Text='<%# Bind("Amount") %>' Width="95%"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" ControlToValidate="amountEdit" ValidationGroup="EditValidation"
ValidationExpression="\d*(\.\d*)?" runat="server" ErrorMessage="Invalid Amount" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="EditValidation" ControlToValidate="amountEdit"
runat="server" ErrorMessage="Amount Required" />
</EditItemTemplate>
<FooterTemplate >
<asp:TextBox ID="amountAdd" runat="server"
Width="95%" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" ControlToValidate="amountAdd" ValidationGroup="AddValidation"
ValidationExpression="\d*(\.\d*)?" runat="server" ErrorMessage="Invalid Amount" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="type" runat="server" Text='<%# Bind("Type") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="typeEdit" runat="server" Text='<%# Bind("Type") %>' Width="95%" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" ControlToValidate="typeEdit" ValidationGroup="EditValidation"
ValidationExpression="\w*" runat="server" ErrorMessage="Invalid Type" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" ValidationGroup="EditValidation" ControlToValidate="typeEdit"
runat="server" ErrorMessage="Type Required" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="typeAdd" runat="server" Width="95%" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" ControlToValidate="typeAdd"
ValidationGroup="AddValidation" ValidationExpression="\w*" runat="server" ErrorMessage="Invalid Type" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProgNum" ReadOnly="true" HeaderText="ProgNum" ControlStyle-Width="95%" />
<asp:TemplateField HeaderText="AckDate">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Convert.ToDateTime(Eval("AckDate")).ToString("MM/dd/yyyy") %>' Width="95%"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" >
<ItemTemplate>
<asp:Label ID="notes" runat="server" Text='<%# Bind("Notes") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="notesEdit" Text='<%# Bind("Notes") %>' runat="server" Width="95%"/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="notesAdd" runat="server" Width="95
%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ActivityDate">
<ItemTemplate>
<asp:Label ID="activityDate" runat="server" Text='<%#Convert.ToDateTime(Eval("activityDate")).ToString("MM/dd/yyyy") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="activityDateEdit" Text='<%#Convert.ToDateTime(Eval("activityDate")).ToString("MM/dd/yyyy") %>' runat="server" CssClass="date" Width="95%" />
<asp:CompareValidator ID="CompareValidator1" runat="server" Type="Date" Operator="DataTypeCheck" ValidationGroup="EditValidation"
ControlToValidate="activityDateEdit" ErrorMessage="Invalid Date" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" ValidationGroup="EditValidation" ControlToValidate="activityDateEdit"
runat="server" ErrorMessage="Date Required" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="activityDateAdd" runat="server" CssClass="date" Width="95%"/>
<asp:CompareValidator ID="CompareValidator2" runat="server" Type="Date" Operator="DataTypeCheck" ValidationGroup="AddValidation"
ControlToValidate="activityDateAdd" ErrorMessage="Invalid Date" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IsVoid">
<ItemTemplate>
<asp:CheckBox ID="isVoid" runat="server" Checked='<%# Eval("IsVoid") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="isVoidEdit" runat="server" Checked='<%# Eval("IsVoid") %>' Width="95%" />
</EditItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="isVoidAdd" runat="server" Width="95%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VoidReason">
<ItemTemplate>
<asp:Label ID="voidReason" runat="server" Text='<%# Bind("VoidReason") %>' Width="95%" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="voidReasonEdit" runat="server" Width="95%" />
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="voidReasonAdd" runat="server" Width="95%" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="false" CommandName="Edit"
Text="<img border=0 src=../Theme/Main/Images/edit.gif alt=Edit>" />
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Delete"
OnClientClick="if(!confirm('Do You Really want to Delete this Order Item?')) return false;"
Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Delete>" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lbAdd" runat="server" CausesValidation="true" CommandName="Update"
ValidationGroup="EditValidation" Text="<img border=0 src=../Theme/Main/Images/check.gif alt=Update>" />
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Cancel"
Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Cancel>" />
</EditItemTemplate>
<FooterStyle HorizontalAlign="Center" VerticalAlign="Top" />
<FooterTemplate>
<asp:LinkButton ID="lbAdd" runat="server" CausesValidation="false" CommandName="Add"
ValidationGroup="AddValidation" Text="<img border=0 src=../Theme/Main/Images/check.gif alt=Add>" />
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="false" CommandName="Cancel"
Text="<img border=0 src=../Theme/Main/Images/delete.gif alt=Cancel>" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:TextBox ID="vendorEdit" runat="server" Text='<%# Bind("Vendor") %>' CssClass="InputTextBox"
Width="100px" />
</EmptyDataTemplate>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbEdit" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
I am trying to use a listview to display and update marks.
The data displays without any issues, however when I click edit, then insert data and try to save the changes, the listview fails to do so and loads in the same state is was prior to the update attempt. Any ideas what is going on?
<asp:SqlDataSource ID="StudentResultsDS" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="SELECT Module_Info.ModuleTitle, Module_Info.UserID, Module_Info.ModuleCode, Modules.ModuleMarks, Modules.MarkID, Modules.ExamMark, Modules.AssignmentMark, Users.SNumber, Lecturer_Records.UserID AS Expr1 FROM Module_Info INNER JOIN Modules ON Module_Info.ModuleID = Modules.ModuleID INNER JOIN Users ON Modules.UserID = Users.UserID INNER JOIN Lecturer_Records ON Users.UserID = Lecturer_Records.UserID WHERE (Lecturer_Records.UserID = #UserID)" UpdateCommand="UPDATE [Modules] SET [ModuleMarks]=#ModuleMarks WHERE [MarkID]=#MarkID" >
<UpdateParameters>
<asp:FormParameter Name="ModuleMarks" Type="String" />
<asp:FormParameter Name="MarkID" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:SessionParameter Name="UserID" SessionField="grabUserID" />
</SelectParameters>
</asp:SqlDataSource>
<!-- list view to display results-->
<header class="jumbotron hero-spacer">
<asp:ListView runat="server" ID="listviewid" DataSourceID="StudentResultsDS" DataKeyNames="ModuleMarks">
<AlternatingItemTemplate>
<span style="">ModuleTitle:
<asp:Label ID="ModuleTitleLabel" runat="server" Text='<%# Eval("ModuleTitle") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
ModuleCode:
<asp:Label ID="ModuleCodeLabel" runat="server" Text='<%# Eval("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:Label ID="ModuleMarksLabel" runat="server" Text='<%# Eval("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:Label ID="ExamMarkLabel" runat="server" Text='<%# Eval("ExamMark") %>' />
<br />
AssignmentMark:
<asp:Label ID="AssignmentMarkLabel" runat="server" Text='<%# Eval("AssignmentMark") %>' />
<br />
SNumber:
<asp:Label ID="SNumberLabel" runat="server" Text='<%# Eval("SNumber") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
<br />
</span>
</AlternatingItemTemplate>
<EditItemTemplate>
<span style="">ModuleTitle:
<asp:TextBox ID="ModuleTitleTextBox" runat="server" Text='<%# Bind("ModuleTitle") %>' />
<br />
UserID:
<asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Bind("UserID") %>' />
<br />
ModuleCode:
<asp:TextBox ID="ModuleCodeTextBox" runat="server" Text='<%# Bind("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:TextBox ID="ModuleMarksTextBox" runat="server" Text='<%# Bind("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel1" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:TextBox ID="ExamMarkTextBox" runat="server" Text='<%# Bind("ExamMark") %>' />
<br />
AssignmentMark:
<asp:TextBox ID="AssignmentMarkTextBox" runat="server" Text='<%# Bind("AssignmentMark") %>' />
<br />
SNumber:
<asp:TextBox ID="SNumberTextBox" runat="server" Text='<%# Bind("SNumber") %>' />
<br />
Expr1:
<asp:TextBox ID="Expr1TextBox" runat="server" Text='<%# Bind("Expr1") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
<br />
<br />
</span>
</EditItemTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">ModuleTitle:
<asp:TextBox ID="ModuleTitleTextBox" runat="server" Text='<%# Bind("ModuleTitle") %>' />
<br />
UserID:
<asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Bind("UserID") %>' />
<br />
ModuleCode:
<asp:TextBox ID="ModuleCodeTextBox" runat="server" Text='<%# Bind("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:TextBox ID="ModuleMarksTextBox" runat="server" Text='<%# Bind("ModuleMarks") %>' />
<br />
ExamMark:
<asp:TextBox ID="ExamMarkTextBox" runat="server" Text='<%# Bind("ExamMark") %>' />
<br />
AssignmentMark:
<asp:TextBox ID="AssignmentMarkTextBox" runat="server" Text='<%# Bind("AssignmentMark") %>' />
<br />
SNumber:
<asp:TextBox ID="SNumberTextBox" runat="server" Text='<%# Bind("SNumber") %>' />
<br />
Expr1:
<asp:TextBox ID="Expr1TextBox" runat="server" Text='<%# Bind("Expr1") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
<br />
<br />
</span>
</InsertItemTemplate>
<ItemTemplate>
<span style="">ModuleTitle:
<asp:Label ID="ModuleTitleLabel" runat="server" Text='<%# Eval("ModuleTitle") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
ModuleCode:
<asp:Label ID="ModuleCodeLabel" runat="server" Text='<%# Eval("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:Label ID="ModuleMarksLabel" runat="server" Text='<%# Eval("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:Label ID="ExamMarkLabel" runat="server" Text='<%# Eval("ExamMark") %>' />
<br />
AssignmentMark:
<asp:Label ID="AssignmentMarkLabel" runat="server" Text='<%# Eval("AssignmentMark") %>' />
<br />
SNumber:
<asp:Label ID="SNumberLabel" runat="server" Text='<%# Eval("SNumber") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
<br />
</span>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<div style="">
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<span style="">ModuleTitle:
<asp:Label ID="ModuleTitleLabel" runat="server" Text='<%# Eval("ModuleTitle") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
ModuleCode:
<asp:Label ID="ModuleCodeLabel" runat="server" Text='<%# Eval("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:Label ID="ModuleMarksLabel" runat="server" Text='<%# Eval("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:Label ID="ExamMarkLabel" runat="server" Text='<%# Eval("ExamMark") %>' />
<br />
AssignmentMark:
<asp:Label ID="AssignmentMarkLabel" runat="server" Text='<%# Eval("AssignmentMark") %>' />
<br />
SNumber:
<asp:Label ID="SNumberLabel" runat="server" Text='<%# Eval("SNumber") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
<br />
</span>
</SelectedItemTemplate>
</asp:ListView>
Try changing it to a gridview which should allow the update to work. Try this code below:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="searchStudentResults" cssClass="table table-hover" AllowSorting="True" OnRowUpdated="GridView1_RowUpdated1" >
<Columns>
<asp:BoundField DataField="StudentNo" HeaderText="StudentNo" SortExpression="StudentNo" ReadOnly="true" />
<asp:BoundField DataField="ExamMark" HeaderText="Exam %" SortExpression="ExamMark" />
<asp:BoundField DataField="AssignmentMark" HeaderText="Assignment %" SortExpression="AssignmentMark" />
<asp:BoundField DataField="ModuleMarks" SortExpression="ModuleMarks" HeaderText="ModuleMarks" ReadOnly="true" DataFormatString="{0:0}" />
<asp:CommandField ShowEditButton="True" ButtonType="Button" EditText="Add Marks" ControlStyle-CssClass="btn btn-primary" ItemStyle-Width="100px" >
<ControlStyle CssClass="btn btn-primary"></ControlStyle>
<ItemStyle Width="100px"></ItemStyle>
</asp:CommandField>
<asp:BoundField DataField="MarkID" ControlStyle-CssClass="hidden" ItemStyle-CssClass="hidden" HeaderStyle-CssClass="hidden" >
<ControlStyle CssClass="hidden"></ControlStyle>
<HeaderStyle CssClass="hidden"></HeaderStyle>
<ItemStyle CssClass="hidden"></ItemStyle>
</asp:BoundField>
</Columns>
<EmptyDataTemplate>
No marks to enter
</EmptyDataTemplate>
</asp:GridView>
I want to hide the edit button in the listview when a session variable is not equal to 2. When session is equal to 2 then I want the edit button to be visible.
My code is below.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="UserStoryID" DataSourceID="ShowProjectsTest">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="StoryLabel" runat="server" Text='<%# Eval("Story") %>' />
</td>
<td>
<asp:Label ID="EstimatedTimeLabel" runat="server" Text='<%# Eval("EstimatedTime") %>' />
</td>
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" Font-Size="Small" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" Font-Size="Small" />
</td>
<asp:Label ID="UserStoryIDLabel" runat="server" Text='<%# Eval("UserStoryID") %>' Visible="false" />
<asp:Label ID="ProjectIDLabel" runat="server" Text='<%# Eval("ProjectID") %>' Visible="false" />
<asp:Label ID="SprintIDLabel" runat="server" Text='<%# Eval("SprintID") %>' Visible="false" />
</tr>
</AlternatingItemTemplate>
</asp:ListView>
Add Visible attribute to the edit button and then toggle it in the code behind.
Mark Up:
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" Font-Size="Small" Visible="false" />
Code Behind:
this.EditButton.Visible = (Session["Key"] as int) == 2;
i have a datalist and a datapager but when i run my program it have error.
Control 'DataList1' does not implement IPageableItemContainer.
what is problem?
<asp:DataList ID="DataList1" runat="server" DataKeyField="id"
DataSourceID="SqlDataSource1">
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
<br />
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
<br />
tedad:
<asp:Label ID="tedadLabel" runat="server" Text='<%# Eval("tedad") %>' />
<br />
group_id:
<asp:Label ID="group_idLabel" runat="server" Text='<%# Eval("group_id") %>' />
<br />
VDate:
<asp:Label ID="VDateLabel" runat="server" Text='<%# Eval("VDate") %>' />
<br />
KDate:
<asp:Label ID="KDateLabel" runat="server" Text='<%# Eval("KDate") %>' />
<br />
gheimat:
<asp:Label ID="gheimatLabel" runat="server" Text='<%# Eval("gheimat") %>' />
<br />
details:
<asp:Label ID="detailsLabel" runat="server" Text='<%# Eval("details") %>' />
<br />
imgae:
<asp:Label ID="imgaeLabel" runat="server" Text='<%# Eval("imgae") %>' />
<br />
"
SelectCommand="SELECT * FROM [Tbl_Kala_Group_No]">
<asp:DataPager ID="DataPager1" runat="server" PagedControlID = "DataList1" PageSize = "4" QueryStringField = "page" >
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
Datapager control does not support for DataList. it works with ListView.
so, Paging for DataList, you have create paging dynamically.
Just give in google : paging for Datalist, you will find lots of resource. Thank you.