I have asp.net gridview control on a webform, which i used to add, edit and delete records of invoice list with four fields of AgreementNO(txtRANO), Invoice No(txtInvNo),Dispute Date(txtDisputeDate), Amount(txtInvAmount).User can add, edit and delete records as required.
I'm trying to validate the text boxes inside grid view item template and edit item template using jQuery since either txtInvNo and txtDisputeDate will have a value per record.
I can identify the text boxes in side empty and footer template as it will be single row and the ID of textboxes doesn't change dynamically.
But the ID s of textboxes changes for example txtInvNo_0,txtInvNo_1 and so on depend on number of rows, and jQuery could not identify using $(this).closest("tr").find("[id$=txtRANumber]") method.
I looked for many examples, and suggested to use css class and identifu each textbox with its css class name. I have applied same css class for all textboxes.
is there any proper way to do this, other wise will end up in number of css class as unique class name required. code below.
<asp:GridView ID="grdCNoteRADetailAdd" runat="server" AutoGenerateColumns="false"
ShowFooter="true" CssClass="grdMain" GridLines="None" DataKeyNames="CNRecID"
OnRowEditing="EditRADetail" OnRowUpdating="UpdateRADetail" OnRowCancelingEdit="CancelEditRADetail"
Width="100%">
<HeaderStyle CssClass="grdheader" />
<RowStyle CssClass="grdItem" VerticalAlign="Top" />
<AlternatingRowStyle CssClass="grdaltItem" VerticalAlign="Top" />
<FooterStyle VerticalAlign="Top" />
<Columns>
<asp:TemplateField HeaderText="RA Number" HeaderStyle-Width="25%" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblRANumber" runat="server" Text='<%# Eval("RANumber")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtRANumber" runat="server" Text='<%# Eval("RANumber")%>' CssClass="txtbox1" ValidationGroup="edRa"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="edRa"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationExpression="[a-zA-Z0-9\s]+$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
<tr>
<td style="width: 25%;">
<asp:TextBox ID="txtRANumber" runat="server" CssClass="txtbox1" Width="90%"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="newNRA"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ErrorMessage="!" ValidationGroup="newNRA"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationExpression="[a-zA-Z0-9\s]+$"></asp:RegularExpressionValidator>
</td>
<td style="width: 25%;">
<asp:TextBox ID="txtInvNo" runat="server" CssClass="txtbox2" Width="90%" ValidationGroup="newNRA"></asp:TextBox>
<asp:RegularExpressionValidator ID="revInvNo" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtInvNo" ValidationGroup="newNRA"
ValidationExpression="^(ri|RI|STI|sti|TI|ti|RIR|rir|OSTI|osti)?\d{7,15}$"></asp:RegularExpressionValidator>
</td>
<td style="width: 20%;">
<asp:TextBox ID="txtDisputeDate" runat="server" CssClass="txtbox2JQDP" Width="75%"></asp:TextBox>
</td>
<td style="width: 20%;">
<asp:TextBox ID="txtCreditAmount" runat="server" CssClass="txtbox1" Width="85%" ValidationGroup="newNRA"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount" ValidationGroup="newNRA"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator9" runat="server" ErrorMessage="!" ValidationGroup="newNRA"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount" ValidationExpression="^\d+(\.\d{1,2})?$"></asp:RegularExpressionValidator>
</td>
<td style="width: 10%;">
<asp:Button ID="btnAddRF" runat="server" Text="Add" OnClick="AddNewRADetail" ValidationGroup="newNRA"/>
</td>
</tr>
<tr>
<td></td>
<td class="tdsubhead2" style="text-align: center;">Total
</td>
<td>
<asp:Label ID="lblCNoteTotal" runat="server" Text=""></asp:Label>
</td>
<td></td>
</tr>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="25%" HeaderText="Invoice No" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="grdItemborder" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblInvNo" runat="server" Text='<%# Eval("InvoiceNo")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtInvNo" runat="server" Text='<%# Eval("InvoiceNo")%>' CssClass="txtbox2" Width="95%" ValidationGroup="edRa"></asp:TextBox>
<asp:RegularExpressionValidator ID="revInvNo" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtInvNo"
ValidationExpression="^(ri|RI|STI|sti|TI|ti|RIR|rir|OSTI|osti)?\d{7,15}$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="20%" HeaderText="Dispute Date" ItemStyle-HorizontalAlign="Center"
HeaderStyle-CssClass="grdItemborder" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblDispute_Date" runat="server" Text='<%# Eval("Dispute_Date")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblDisputeDate" runat="server" Text='<%# Eval("Dispute_Date")%>' Visible='<%# IIf(Eval("IsInvoice") = True, True, False)%>'></asp:Label>
<asp:TextBox ID="txtDisputeDate" runat="server" CssClass="txtbox2JQDP" Width="75%" Text='<%# Eval("Dispute_Date")%>' Visible='<%# If(Eval("IsInvoice") = True, False, True)%>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="20%" HeaderText="Credit Amount" HeaderStyle-CssClass="grdItemborder"
ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:Label ID="lblCreditAmount" runat="server" Text='<%# Eval("CNAmount")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtCreditAmount" runat="server" Text='<%# Eval("CNAmount")%>' CssClass="txtbox1" Width="90%" ValidationGroup="edRa"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="!" ValidationGroup="edRa"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount" ValidationExpression="^\d+(\.\d{1,2})?$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<%--<asp:CommandField ShowEditButton="True" />--%>
<asp:TemplateField ShowHeader="False" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit" ValidationGroup="vgEdit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<table style="width: 100%">
<tr>
<td>
<asp:LinkButton ID="lnkUpdate" runat="server" CausesValidation="True" CommandName="Update"
Text="Update" ValidationGroup="edRa"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkRemoveRF" runat="server" CommandArgument='<%# Eval("CNRecID")%>'
Text="Delete" OnClick="DeleteRADetail" CausesValidation="false"></asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate>
<HeaderStyle Width="5%" />
</asp:TemplateField>
<%--<asp:TemplateField HeaderStyle-Width="10%" HeaderStyle-CssClass="grdItemborder" ItemStyle-CssClass="grdItemborder">
<ItemTemplate>
<asp:LinkButton ID="lnkRemoveRF" runat="server" CommandArgument='<%# Eval("CNRecID")%>'
Text="Delete" OnClick="DeleteRADetail" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>--%>
</Columns>
<EmptyDataTemplate>
<tr>
<td class="tdsubhead2" style="width: 25%; text-align: center;">RA Number
</td>
<td class="tdsubhead2" style="width: 25%; text-align: center;">Invoice No
</td>
<td class="tdsubhead2" style="width: 20%; text-align: center;">Dispute Date
</td>
<td class="tdsubhead2" style="width: 20%; text-align: center;">Credit Amount
</td>
<td style="border: 0px solid grey; width: 10%;"></td>
</tr>
<tr>
<td style="text-align: center">
<asp:TextBox ID="txtRANumber" runat="server" CssClass="txtbox1" ValidationGroup="newRa" Width="90%" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="newRa"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator10" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber"
ValidationExpression="[a-zA-Z0-9\s]+$" ValidationGroup="newRa"></asp:RegularExpressionValidator>
</td>
<td style="vertical-align: top; text-align: center">
<asp:TextBox ID="txtInvNo" runat="server" CssClass="txtbox2" ValidationGroup="newRa" Width="90%" />
<asp:RegularExpressionValidator ID="revInvNo" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtInvNo"
ValidationExpression="^(ri|RI|STI|sti|TI|ti|RIR|rir|OSTI|osti)?\d{7,15}$" ValidationGroup="newRa"></asp:RegularExpressionValidator>
</td>
<td style="vertical-align: top; text-align: center">
<asp:TextBox ID="txtDisputeDate" runat="server" CssClass="txtbox2JQDP" Width="75%"></asp:TextBox>
</td>
<td style="text-align: center">
<asp:TextBox ID="txtCreditAmount" runat="server" CssClass="txtbox1" Width="75%" ValidationGroup="newRa" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="!"
ValidationGroup="newRa" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator12" runat="server"
ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtCreditAmount"
ValidationExpression="^\d+(\.\d{1,2})?$" ValidationGroup="newRa"></asp:RegularExpressionValidator>
</td>
<td style="width: 10%">
<asp:Button ID="btnAddRF" runat="server" Text="Add" OnClick="AddNewRADetail" CommandName="emptyInsert"
CausesValidation="true" CssClass="buttonScreenSpec" ValidationGroup="newRa" />
</td>
</tr>
<tr>
<td></td>
<td></td>
<td class="tdsubhead2" style="text-align: center;">Total
</td>
<td>
<asp:Label ID="lblCNoteTotal" runat="server" Text=""></asp:Label>
</td>
<td></td>
</tr>
</EmptyDataTemplate>
</asp:GridView>
JQuery Code Below/
/Add New Record
$("[id$=grdCNoteRADetailAdd] [id$=btnAddRF]").click(function () {
var raRow = $(this).closest("tr");
alert($(this).closest("tr input[type='text']").length);
var txtRaNo = raRow.find("[id$=txtRANumber]");
var txtInvNo = raRow.find("[id$=txtInvNo]");
var txtDisDate = raRow.find("[id$=txtDisputeDate]");
if ($.trim(txtRaNo.val()) != "")
{
if ($.trim(txtInvNo.val()) == "" && $.trim(txtDisDate.val()) == "")
{
var msg = "Both Invoive No and Dispute Date cannot be empty.\nIf system generated invoice is not available, specify the date when was the dispute happend.\n ";
msg += "For example : Date when the tarffic fine was charged directly to customer by police..!"
alert(msg);
return false;
}
}
return true;
});
//Edit Record using Update Link button
//This does not work as txtRANumber,txtInvNo and txtDisputeDate are dynamically gaving index at the end as txtDisputeDate_0,1 etc based on number of rows in the grid
$('#<%=grdCNoteRADetailAdd.ClientID %> a:contains(Update)').click(function () {
var raRow = $(this).closest("tr");
var txtRaNo = raRow.find("[id$=txtRANumber]");
var txtInvNo = raRow.find("[id$=txtInvNo]");
var txtDisDate = raRow.find("[id$=txtDisputeDate]");
alert(txtRaNo.attr("id"));
if ($.trim(txtRaNo.val()) != "") {
if ($.trim(txtInvNo.val()) == "" && $.trim(txtDisDate.val()) == "") {
//alert('fuck2');
var msg = "Both Invoive No and Dispute Date cannot be empty.\nIf system generated invoice is not available, specify the date when was the dispute happend.\n ";
msg += "For example : Date when the tarffic fine was charged directly to customer by police..!"
alert(msg);
return false;
}
}
return true;
});
I have found the answer for the issue and post here, to help others.
Note: 1. Text box placed inside will be created a dynamic ID as "textboxName(number)". So JQuery will not identify the text box using its id.
I added a css class name (same as textbox ID) along with actual css class name.
for example, my textbox ID ="txtRANumber" and CssClass="txtRANumber txtbox1".
here txtbox1 is the css class , and txtRANumber class i added to identify the textbox using its class name using JQuery.Gridview code extract and JQuery code extract are below.
$("[id*=grdCNoteRADetailAdd] [id*=lnkUpdate]").click(function () {
var raNo = $('.txtRANumber').val(); // txtRANumber text box identifiied using its css class name
var invNo = $('.txtInvNo').val();
var disDate = $('.txtbox2JQDP').val();
if ($.trim(raNo) == "") {
var msg="Enter RA number"
alert(msg);
return false;
}
}
return true;
});
<EditItemTemplate>
<asp:TextBox ID="txtRANumber" runat="server" Text='<%# Eval("RANumber")%>' CssClass="txtRANumber txtbox1" ValidationGroup="edRa"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="!"
Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationGroup="edRa"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="!" Display="Dynamic" CssClass="rqrdtxt" ControlToValidate="txtRANumber" ValidationExpression="[a-zA-Z0-9\s]+$" ValidationGroup="edRa"></asp:RegularExpressionValidator>
</EditItemTemplate>
Related
I want to validate at least one checkbox select when edit the listview
when the list view have more than one record the validation is not working but its work if the listview have one record.
I think my code not detect the edited record, when its more than one.
what is the problem with this code can some one help with it?
Protected Sub UpdateButton_Click(sender As Object, e As EventArgs)
'get data from chekced checkbox
Dim ChkValue As New List(Of String)()
For Each item As ListViewItem In ListView1.Items
Dim ck1 As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
Dim ck2 As CheckBox = DirectCast(item.FindControl("CheckBox2"), CheckBox)
Dim ck3 As CheckBox = DirectCast(item.FindControl("CheckBox3"), CheckBox)
Dim vl As RequiredFieldValidator = DirectCast(item.FindControl("RequiredFieldValidator1"), RequiredFieldValidator)
If ck1.Checked Or ck2.Checked Or ck3.Checked Then
vl.Enabled = False
sdstt.Update()
Else
vl.Enabled = True
End If
Next
End Sub
<asp:ListView ID="ListView1" runat="server" DataSourceID="sdstt" DataKeyNames="ID" >
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" CausesValidation="true" ValidationGroup="vgrpSaveContact" CommandName="Update" OnClick="UpdateButton_Click" runat="server" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<asp:RequiredFieldValidator Font-Size="6pt" ID="RequiredFieldValidator3" runat="server" ControlToValidate="nameTextBox"
ErrorMessage="first name" SetFocusOnError="true" ValidationGroup="vgrpSaveContact"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revOnlyAlphabetical" runat="server" Font-Size="6pt" ValidationGroup="vgrpSaveContact"
ValidationExpression="^([^0-9]+)$" ControlToValidate="nameTextBox"
ErrorMessage="Invalid Name" Font-Bold="true" ForeColor="Red"></asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="ageTextBox" runat="server" Text='<%# Bind("age") %>' />
</td>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("chk1") %>' />
</td>
<td>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("chk2") %>' />
</td>
<td>
<asp:CheckBox ID="chkCheckBox3" runat="server" Checked='<%# Bind("chk3") %>' />
<asp:TextBox ID="txtchk" runat="server" Visible="false" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ValidationGroup="vgrpSaveContact" Enabled="false" runat="server"
ControlToValidate="txtchk" ErrorMessage="RequiredFieldValidator">
</asp:RequiredFieldValidator>
</td>
</tr>
</EditItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
</td>
<td>
<asp:Label ID="ageLabel" runat="server" Text='<%# Eval("age") %>' />
</td>
<td>
<asp:CheckBox ID="chkCheckBox" runat="server" Checked='<%# Eval("chk") %>' Enabled="false" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">ID</th>
<th runat="server">name</th>
<th runat="server">age</th>
<th runat="server">chk</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
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 want to generate a dynamic id of my datepicker. below jquery function shows the datetimepicker as the id is defined as static.
$(function () {
var dates = $("#ContentPlaceHolder1_gvdLCStatus_txtInvoiceDate_0").datepicker(
{
dateFormat: 'dd/mm/yy',
defaultDate: '+1w',
changeMonth: false,
numberOfMonths: 1,
showOn: 'both',
buttonImage: 'Images/calendar_month.png',
buttonImageOnly: true,
onSelect: function (selectedDate) {
var option = this.id == "ContentPlaceHolder1_gvdLCStatus_txtInvoiceDate_0" ? "minDate" : "maxDate",
instance = $(this).data("datepicker");
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
});
I want to generate a dynamic ID for the DatePicker. and How that ive tried various time but couldnt find the actual way of doing.Thanks.
<asp:GridView ID="gvdLCStatus" runat="server" DataKeyNames="LCID" AutoGenerateColumns="false"
AllowPaging="True" PageSize="4" EmptyDataText="No Record Found" CssClass="mGrid"
OnPageIndexChanging="gvdLCStatus_PageIndexChanging" OnRowCommand="gvdLCStatus_RowCommand"
OnSelectedIndexChanged="gvdLCStatus_SelectedIndexChanged" OnRowDataBound="gvdLCStatus_RowDataBound"
OnRowCreated="gvdLCStatus_RowCreated">
<AlternatingRowStyle CssClass="test" />
<Columns>
<asp:TemplateField HeaderText="LC Number">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("LCID") %>' Visible="false"></asp:Label>
<a href="#" onclick="linkbtnTest('<%# "#"+Eval("LCNumber") %>')">
<%# Eval("LCNumber") %></a>
<%-- <div id='<%# Eval("ShipmentID") %>' style="display: none;">
</div>--%>
<div id='<%# Eval("LCNumber") %>' style="display: none;">
<asp:GridView ID="gvShipmentStatus" runat="server" AutoGenerateColumns="false" DataKeyNames="ShipmentID"
OnRowCommand="gvShipmentStatus_RowCommand" OnRowDataBound="gvShipmentStatus_RowDataBound"
CssClass="mGrid">
<Columns>
<asp:BoundField DataField="InvoiceNumber" HeaderText="Invoice Number" />
<asp:BoundField DataField="InvoiceDate" HeaderText="Invoice Date" />
<asp:BoundField DataField="BLNumber" HeaderText="B/L Number" />
<asp:BoundField DataField="BLDate" HeaderText="B/L Date" />
<asp:BoundField DataField="VesselName" HeaderText="Vessel Name" />
<asp:BoundField DataField="VoyageNumber" HeaderText="Voyage Number" />
<asp:BoundField DataField="DueDate" HeaderText="Due Date" />
<asp:BoundField DataField="ContractedShipmentSchedule" HeaderText="Shipment Schedule" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="ImgShipmentDelete" runat="server" ImageUrl='<%# isDelete_img(Session["isAdmin"].ToString()) %>'
Enabled='<%# isDelete(Session["isAdmin"].ToString()) %>' CommandName="DeleteShipmentRecord"
CommandArgument='<%# Eval("ShipmentID") %>' AlternateText="DeleteShipmentRecord"
OnClientClick="return confirm_delete();" Style='<%# delete_style(Session["isAdmin"].ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<%-- <asp:ImageButton ID="ImgShipmentEdit" runat="server" ImageUrl="~/Images/edit.png"
CommandName="EditShipmentRecord" ImageAlign="Middle" CommandArgument='<%# Eval("ShipmentID") %>'
AlternateText="EditShipmentRecord" OnClientClick='linkbtnTest(<%# Eval("ShipmentID) %>)' />
--%>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="EditShipmentRecord"
CommandArgument='<%# Eval("ShipmentID")+":"+Eval("LCStatusID")%>'>
<%--<asp:Label ID="Label2" runat="server" Text='<%# Eval("ShipmentID") %>' Visible="true"></asp:Label>--%> <img src="Images/edit.png" alt="Edit" />
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<%--</div>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ContractNumber" HeaderText="Contract Number" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:BoundField DataField="Qty" HeaderText="Quantity" />
<asp:TemplateField>
<ItemTemplate>
Add Shipment Status
<div id='<%# Eval("LCID") %>' style="display: none;">
<table>
<tr>
<td class="td_records" style="padding-top: 5px;">
Invoice Number
</td>
<td class="td_records" style="padding-top: 5px;">
Invoice Date (dd/mm/yyyy)
</td>
<td class="td_records" style="padding-top: 5px;">
B/L Number
</td>
<td class="td_records" style="padding-top: 5px;">
B/L Date (dd/mm/yyyy)
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtInvoiceNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtInvoiceDate" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtBLNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtBLDate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="td_records" style="padding-top: 5px;">
VesselName
</td>
<td class="td_records" style="padding-top: 5px;">
VoyageNumber
</td>
<td class="td_records" style="padding-top: 5px;">
DueDate (dd/mm/yyyy)
</td>
<td class="td_records" style="padding-top: 5px;">
ShipmntSchedule (dd/mm/yyyy)
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtVesselName" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtVoyageNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtDueDate" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtShipmntSchedule" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-top: 10px;">
<asp:Button ID="btnSubmitShipment" runat="server" Text="Submit" CommandName="Select"
OnCommand="btnSubmitShipment_Command" CssClass="btnSubmitCSS" />
<asp:Button ID="btnResetShipmentRecord" runat="server" Text="Reset" CssClass="btnSubmitCSS" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" ImageUrl='<%# isDelete_img(Session["isAdmin"].ToString()) %>'
Enabled='<%# isDelete(Session["isAdmin"].ToString()) %>' CommandName="DeleteRecord"
CommandArgument='<%# Eval("LCID") %>' AlternateText="DeleteRecord" OnClientClick="return confirm_delete();"
Style='<%# delete_style(Session["isAdmin"].ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Images/edit.png" CommandName="EditRecord"
CommandArgument='<%# Eval("LCID") %>' AlternateText="EditRecord" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pgr" />
</asp:GridView>
As an option you may use such selector:
var dates = $("[id*='txtInvoiceDate']", "#<%= gvdLCStatus.ClientID %>")
But better consider to set CssClass property on textboxes and use class selector
Why do you select by id? Why don't you go with class name? $('.datebox').dateTimepicker(...
i found an alternate of validating it with asp.net required field validators. No other option was there and had to maintain the time constraint.
Thanks Guys.
<asp:ListView ID="lvWallPosts" runat="server"
onitemcommand="lvWallPosts_ItemCommand" InsertItemPosition="LastItem">
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblWallPosts"
style="width:460px">
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtMessage" runat="server"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<tr id="Tr2" style="height:72px" runat="server">
<td valign="top" class="EmployeeInfo">
<p>
<div class="wallmark"><asp:Image ID="imgFile" runat="server" CssClass="friendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"ByUsername").ToString() %>' />
<asp:Label ID="lblFrom" runat="server" Text='<%#Eval("ByUsername") %>' Font-Size="0.9em" Font-Underline="false" /><br />
<asp:Label ID="lblMessage" runat="server" Text='<%#Eval("Message") %>' Font-Size="0.9em" Font-Underline="false"/></div>
<asp:LinkButton CssClass="shareText" runat="server" ID="lblComment" CommandArgument='<%# Eval("Id") %>' CommandName="Insert" Font-Size="0.9em" Font-Underline="false">Comment</asp:LinkButton>
<asp:LinkButton CssClass="shareText" runat="server" ID="lbShare" CommandArgument='<%# Eval("Id") %>' CommandName="Share" Font-Size="0.9em" Font-Underline="false">Share</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I cant see the txtMessage control when I click on linkbutton comment.
try setting the linkbutton's commandname to "InitInsert" instead of "Insert"
I have two datalists. One works like a menu where you click on a link to fill the othe datalist.
I also have added a next and previous linkbutton to move between the different "pages" so that you do not have to change using the menu datalist.
Now in code behind depending on which values I get from the database I add a RegularExpressionValidator.
This works great until I want to use the next button (or previous for that matter). Even if all the controls that are checked are valid when compared with the RegularExpressionValidator I never get to load the new values.
The next and previous buttons fires the datalist selected index change event and then I check if it is the previous or next button that was clicked.
But the previous and next buttons are numb. They don't even fire the event.
It is like clicking on the background. Nothing happens.
I have chcked the PageIs.Valid and it is true.
Does anyone have a clue what it could be that is causing this behavior?
Thanks in advance!
Some of the texts down there is in Swedish but it shouldn't matter for the code.
rev_checkfieldvalue.ControlToValidate = "tb_detailValue";
switch (iDataTypeId)
{
case 2:
rev_checkfieldvalue.ValidationExpression = #"^\d*[0-9 ]+$";
rev_checkfieldvalue.Text = "Fältet får endast innehålla siffror och mellanslag.";
break;
case 3:
break;
case 4:
break;
case 5:
rev_checkfieldvalue.ValidationExpression = #"\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*";
rev_checkfieldvalue.Text = "Fältet får endast innehålla en e-postadress.";
break;
}
e.Item.Controls.AddAt(32, rev_checkfieldvalue);
<asp:DataList ID="dl_componentInfo" DataKeyField="ComponentId" runat="server" OnItemDataBound="dl_componentInfo_OnItemDataBound" OnItemCommand="dl_componentInfo_OnItemCommand">
<ItemTemplate>
<table>
<tr>
<td colspan="2"><asp:Label ID="lb_componentName" SkinID="lblHeader" runat="server" Text='<%# Eval("ComponentName") %>' /></td>
</tr>
<tr>
<td colspan="2">Fält markerade med * är obligatoriska</td>
</tr>
<tr>
<td> </td>
<td>
<asp:DataList ID="dl_details" OnItemDataBound="dl_details_OnItemDataBound" runat="server">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lbl_detailName" Text='<%# Eval("DetailName") %>' runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_custDetName" runat="server" />
</td>
<td align="left">
<%--Always hidden values--%>
<asp:Label ID="lbl_detailTypeId" Visible="false" Text='<%# Eval("DetailTypeId") %>' runat="server" />
<asp:Label ID="lbl_detailId" Visible="false" Text='<%# Eval("DetailId") %>' runat="server" />
<asp:Label ID="lbl_dataTypeId" Visible="false" Text='<%# Eval("DataTypeId") %>' runat="server" />
<asp:Label ID="lbl_customerEventValueId" Visible="false" Text='<%# Eval("CustomerEventValueId") %>' runat="server" />
<asp:Label ID="lbl_reqFld" Visible="false" Text='<%# Eval("ReqFld") %>' runat="server" />
<%--Sometimes visible values--%>
<asp:Label ID="lbt_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbtb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbth_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbc_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:DropDownList ID="dd_detailValue" Visible="false" runat="server"></asp:DropDownList>
<%--Om det ska gå att markera/avmarkera alla så använd AJAX--%>
<asp:CheckBoxList ID="cbl_detailValue" RepeatDirection="Horizontal" RepeatLayout="flow" Visible="false" runat="server" />
<asp:CheckBox ID="cb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="tb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="ta_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
<table width="600">
<tr>
<td>
<asp:LinkButton id="lb_previous" Text="Föregående" CommandName="Previous" runat="server"/>
</td>
<td>
<asp:LinkButton id="lb_next" Text="Nästa" CommandName="Next" runat="server"/>
</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
I thought I solved the issue but it just stopped checking.
So for case two you accept any non-empty string of digits and spaces.
Is that your intent?