<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="opendiarysource" Font-Size="Small" style="font-size: 8pt; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid; color: black;" AllowSorting="True" >
<Columns>
<asp:TemplateField HeaderText="Date Added" SortExpression="added7">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("added7") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<br />
<asp:Label ID="Label1" runat="server" Text='<%# Bind("added7") %>'></asp:Label><br />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ByWhom" HeaderText="Added By" SortExpression="ByWhom" />
<asp:BoundField DataField="BOOKNO" HeaderText="Book #" SortExpression="BOOKNO" />
<asp:BoundField DataField="ClearedBy" HeaderText="Cleared By" SortExpression="ClearedBy" Visible="False" />
<asp:BoundField DataField="Done7" HeaderText="Date Done" SortExpression="Done7" Visible="False" />
<asp:BoundField DataField="ForWhom" HeaderText="For Whom" SortExpression="ForWhom" />
I want this last field to show up as a row underneath instead of a column.
<asp:TemplateField HeaderText="Note" SortExpression="Text">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Text") %>'></asp:TextBox>
</EditItemTemplate
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Text") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Try to use ListView instead of GridView, if that would be an option for you. That has lot of templating features.
The Templates would like:
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("col1") %>' ></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("col2") %>' ></asp:Label>
</td>
</tr>
<tr>
<td colspan="10">
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Text") %>' ></asp:Label>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("col1") %>' ></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("col2") %>' ></asp:Label>
</td>
</tr>
<tr>
<td colspan="10">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Text") %>' ></asp:TextBox>
</td>
</tr>
</EditItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
Convert all the rows to columns by this way....
public DataTable ConvertColumnsAsRows(DataTable dt)
{
DataTable dtnew = new DataTable();
for (int i = 0; i <= dt.Rows.Count; i++)
{
dtnew.Columns.Add(Convert.ToString(i));
}
DataRow dr;
for (int j = 0; j < dt.Columns.Count; j++)
{
dr = dtnew.NewRow();
dr[0] = dt.Columns[j].ToString();
for (int k = 1; k <= dt.Rows.Count; k++)
dr[k] = dt.Rows[k - 1][j];
dtnew.Rows.Add(dr);
}
return dtnew;
}
This function is used to convert columns to rows
Related
I have a gridview in my APSX that looks like below:
I want to be able to stretch the 'Comments' data cells so they stretch to the bottom of each section (stretch an extra 3 cells down)
I have tried numerous things and nothing seems to be working for me, I was wondering if anyone could point me in the right direction to do this.
This is the code I am using for my Gridview..
...
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20%" HeaderText="Project Name">
<ItemTemplate>
<asp:Label ID="ProjectNameLab" runat="server" Text='<%# Bind("[Project Name]")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20%" HeaderText="Customer Name" SortExpression="Customer Name">
<ItemTemplate>
<asp:Label ID="CustomerNameLab" runat="server" Text='<%# Bind("[Customer Name]")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10%" HeaderText="Month" SortExpression="Month">
<ItemTemplate>
<asp:Label ID="MonthLab" runat="server" Text='<%# Bind("Month")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="10%" HeaderText="App Date" SortExpression="ApplicationDate">
<ItemTemplate>
<asp:Label ID="ApplicationDateLab" runat="server" Text='<%# Bind("ApplicationDate")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="12%" HeaderText="Value" SortExpression="ThisApp">
<ItemTemplate>
<asp:LinkButton ID="ThisAppLab" runat="server" Text='<%# Bind("ThisApp")%>'></asp:LinkButton>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
Enabled="True" PopupControlID="EditPopup1" TargetControlID="ThisAppLab"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20%" HeaderText="Comments" SortExpression="Comments">
<ItemTemplate>
<asp:Label ID="CommentsLab" runat="server" Text='<%# Bind("Comments")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true">
<ItemTemplate>
<tr>
<td colspan="5">
<td>
<asp:Label Style="padding: 0px 0px 0px 0px" Width="100%" ID="PaidLbl" runat="server" Text='<%# Bind("Paid")%>'></asp:Label>
<itemstyle width="100%" />
</td>
</td>
</tr>
<tr>
<td colspan="5"></td>
<td>
<asp:Label Style="padding: 0px 0px 0px 0px" Width="100%" ID="DifferenceLbl" runat="server"></asp:Label>
<itemstyle width="100%" />
</td>
</tr>
<tr>
<td colspan="5"></td>
<td>
<asp:Label Style="padding: 0px 0px 0px 0px" Width="100%" ID="DateFP" runat="server" Text='<%# Bind("Date")%>'></asp:Label>
<itemstyle width="100%" />
</td>
</tr>
<tr>
<td colspan="5"></td>
<td>
<asp:Label Style="padding: 0px 0px 0px 0px; visibility: hidden" Width="100%" ID="BlankRowLbl" Text="Blank" runat="server"></asp:Label>
<itemstyle width="100%" />
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Any help or advice would be appreciated, Thank you in advance.
Within your template field you should add a table and set the row span to the amount of rows that you want. Something like :
<asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20%" HeaderText="Comments" SortExpression="Comments">
<ItemTemplate>
<table>
<tr>
<td rowspan="3">
<asp:Label ID="CommentsLab" runat="server" Text='<%# Bind("Comments")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
EDIT: Try putting the cell in the other template field as another column instead of its own template field.
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>
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 GridView that is editable with an entitydatasource, if my users want to delete the text in one of the fields they cannot. They can replace the text with a space which then saves, but if the textbox is completely empty the save operation doesn't do anything.
How do I combat this?
Thanks
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=CS3Entities" DefaultContainerName="CS3Entities"
EnableFlattening="False" EnableUpdate="True"
EntitySetName="ProductAlertStatuses"
Where="it.AlertType != '0'"
OrderBy="it.Department DESC, it.AlertType DESC"/>
<br/>
<asp:GridView runat="server" ID="ActionPlanGV"
DataSourceID="EntityDataSource1"
OnDataBound="ActionPlanGV_OnRowDataBound"
CssClass="mGrid visibleGrid"
AutoGenerateColumns="False"
DataKeyNames="ProductStatusID">
<Columns>
<asp:TemplateField SortExpression="Department" ItemStyle-CssClass="center">
<HeaderTemplate>
<asp:Label ID="DepartmentColHeader" ToolTip="Moulding or Finishing Department" runat="server" Text="Dept" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="DepartmentColtxt" runat="server" Text='<%# Eval("Department") %>' />
</ItemTemplate>
<ItemStyle CssClass="center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField SortExpression="AlertType" ItemStyle-CssClass="center">
<HeaderTemplate>
<asp:Label ID="AlertTypeColHeader" ToolTip="Alert Type" runat="server" Text="Alert" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="AlertTypeColtxt" runat="server" Text='<%# ItemDAL.GetAlertStatusColourFromNumber(Eval("AlertType").ToString()) %>' />
</ItemTemplate>
<ItemStyle CssClass="center"></ItemStyle>
</asp:TemplateField>
<%--<asp:BoundField DataField="DateAlertRaised" DataFormatString="{0:d}" HeaderText="Date Alert Raised" ReadOnly="True" SortExpression="DateAlertRaised" />--%>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="ItemIDHeader" ToolTip="Item Code" runat="server" Text="Item" />
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="ItemID"
runat="server"
Text='<%# Eval("ItemID") %>'
NavigateUrl='<%# Url.GetUrl("ViewItem", Eval("ItemID")) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Scrap /Parts" ItemStyle-Width="7%" SortExpression="ActionPlanScrapParts">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" TextMode="MultiLine" Width="75" Height="75" runat="server" Text='<%# Bind("ActionPlanScrapParts") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ActionPlanScrapParts") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Defect Issue / Description" ItemStyle-Width="15%" SortExpression="ActionPlanDefectDescription">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanDefectDescription") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ActionPlanDefectDescription") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Root Cause" ItemStyle-Width="15%" SortExpression="ActionPlanRootCause">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanRootCause") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ActionPlanRootCause") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Corrective Action<div style='font-size:8px;line-height:8px;'>FN16, FN17, FN03, FN05,<br/>Change Note Number</div>-Who? Due By?" ItemStyle-Width="20%" SortExpression="ActionPlanCorrectiveAction">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanCorrectiveAction") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("ActionPlanCorrectiveAction") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Preventative Action<br/>-Who? Due By?" ItemStyle-Width="15%" SortExpression="ActionPlanPreventativeAction">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" TextMode="MultiLine" Width="100" Height="75" runat="server" Text='<%# Bind("ActionPlanPreventativeAction") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("ActionPlanPreventativeAction") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reviewed & Closed" ItemStyle-Width="10%" SortExpression="ActionPlanReviewedClosed">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" TextMode="MultiLine" Width="75" Height="75" runat="server" Text='<%# Bind("ActionPlanReviewedClosed") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("ActionPlanReviewedClosed") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ItemStyle-CssClass="noprint" HeaderStyle-CssClass="noprint">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" Text="Save"/>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel"/>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lbEdit2" runat="server" CommandName="Edit" Text="Edit"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
There is one codebehind method, but that doesn't touch the data:
protected void ActionPlanGV_OnRowDataBound(object sender, EventArgs eventArgs)
{
foreach (GridViewRow row in ActionPlanGV.Rows)
{
var alertTypeColtxt = (Label)row.FindControl("AlertTypeColtxt");
if (alertTypeColtxt != null)
{
if (alertTypeColtxt.Text == "Red")
alertTypeColtxt.Text = "<svg width='18' height='18'><circle cx='9' cy='9' r='8' fill='red' /></svg>";
if (alertTypeColtxt.Text == "Amber")
alertTypeColtxt.Text =
"<svg width='15' height='15'><rect x='0' y='0' height='15' width='15' fill='orange' /></svg>";
if (alertTypeColtxt.Text == "Green")
alertTypeColtxt.Text = "<svg width='18' height='18'><circle cx='9' cy='9' r='8' fill='green' /></svg>";
}
}
}
<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"