What I need: TARGET or ACTUAL on first line and rest on next line.
What I have till now
I have this gridview templatefield in asp.net
<asp:TemplateField HeaderStyle-CssClass="headerStyle" HeaderText="TARGET Approval Date" FooterStyle-CssClass="alternateStyler" ItemStyle-CssClass="alternateStyler" ItemStyle-Width="8%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="dtTgtApprDate" CssClass="Datetext" Width="98%" Height="23px" runat="server" Text='<%# Eval("Phase2")%>'></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="dtTgtApprDate2" CssClass="Datetext" Width="98%" Height="23px" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-CssClass="headerStyle" HeaderText="ACTUAL Approval Date" FooterStyle-CssClass="alternateStyler" ItemStyle-CssClass="alternateStyler" ItemStyle-Width="8%" ItemStyle-VerticalAlign="Top" FooterStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:TextBox ID="dtActApprDate" CssClass="Datetext" Width="98%" Height="23px" runat="server" Text='<%# Eval("Phase3")%>'></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="dtActApprDate2" CssClass="Datetext" Width="98%" Height="23px" runat="server">
</asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
I have put this css for HeaderStyle-CssClass="headerStyle"
.headerStyle {
text-justify:distribute;
}
Since the header is HTML also, you can just put a <br> in it.
<asp:TemplateField HeaderText="TARGET<br>ApprovalDate">
Related
I am having an issue with Visual Studio. I have a page with a GridView. The code behind recognizes the GridView fine, but none of the elements within it. I tried putting a label before the GridView and it was able to recognize it. This would imply there is some error in my aspx code file, but I have looked it over and all looks well to me.
I have tried deleting .designer.cs file and 'Converting to Web Application'. I have tried copying the code, deleting the files, and recreating them. I have also tried numerous cleans and rebuilds and restarting Visual Studio. Still, no success. I would greatly appreciate any guidance.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True" CodeBehind="users.aspx.cs" Inherits="Ticket_System.admin.users" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:GridView ID="userGrid" runat="server" OnRowEditing="userGrid_RowEditing" DataKeyNames="END_USER_ID" AutoGenerateEditButton="True" AutoGenerateColumns="false" OnRowUpdating="userGrid_RowUpdating" OnRowCancelingEdit="userGrid_RowCancelingEdit">
<Columns>
<asp:TemplateField HeaderText="User #">
<ItemTemplate>
<asp:Label ID="idLabel" runat="server" Text='<%# Bind("END_USER_ID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="idText" runat="server" Enabled="false" Text='<%# Bind("END_USER_ID") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Access">
<ItemTemplate>
<asp:Label ID="accessLabel" runat="server" Text='<%# Bind("ACCESS_ROLE.DESCRIPTION") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User">
<ItemTemplate>
<asp:Label ID="userLabel" runat="server" Text='<%# Bind("USER_NAME") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="userText" runat="server" Text='<%# Bind("USER_NAME") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password">
<ItemTemplate>
<asp:Label ID="passLabel" runat="server" Text='<%# Bind("PASSWORD") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="passText" runat="server" Text='<%# Bind("PASSWORD") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First">
<ItemTemplate>
<asp:Label ID="firstLabel" runat="server" Text='<%# Bind("FIRST_NAME") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="firstText" runat="server" Text='<%# Bind("FIRST_NAME") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last">
<ItemTemplate>
<asp:Label ID="lastLabel" runat="server" Text='<%# Bind("LAST_NAME") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lastText" runat="server" Text='<%# Bind("LAST_NAME") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Active">
<ItemTemplate>
<asp:Label ID="activeLabel" runat="server" Text='<%# Bind("ACTIVE_FLAG") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="activeText" runat="server" Text='<%# Bind("ACTIVE_FLAG") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Content>
EDIT: Just wanted to clarify something. What I mean is that the controls are not even recognized at all in the code behind. For example firstLabel.Text gives me an "does not exist in current context" error.
Try using the FindControl() method.
foreach(GridViewRow row in userGrid.Rows) {
if(row.RowType == DataControlRowType.DataRow) {
string idText = (string)row.FindControl("idText");
}
}
I want to create a table as below to interact with database to retrieve, delete, update data.
My output in design view is very messy. And when i try to run the page i receive the following error:
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Please advise me for enhancement based on below data table and my coding.
.aspx:
<div class="modal-bg">
<asp:GridView ID="GridView1" runat="server" EnableEventValidation="false"
BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
CellPadding="4" Width="426px">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
UsernameLast Login Status
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("UserName") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate>
Active Role
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ActiveRole") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate >
Full name
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("FullName") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate>
Email Address
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("EmailAddress") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate>
Last Login Status
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("Last Login Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<button id="newuserbutton" onclick="return newuserbutton_onclick()">
Create New User</button>
Thank you for helps.
Did you actually try to place your control inside the <form runat="server"></form> tags?
Surround your html code with tag => <form runat="server"> ... </form>
I have an ajax tab which inside has a grid, on this grid there is a check box where the user has the ability to check it and assign it to a technician, but for some reason im unable to reference the control, the grid has a total of 4 rows so there is data there, this is my code which is run of a button click
protected void btnAllocate_click(object sender, EventArgs e)
{
foreach (System.Web.UI.Control s in tbHappyCall.Controls)
{
foreach (GridViewRow Row in gvHappyCall.Rows)
{
CheckBox chkAllocate = (CheckBox)Row.FindControl("chkAllocate");
if (chkAllocate.Checked)
{
HyperLink lblOrderID = (HyperLink)Row.FindControl("hyperOrderID");
HappyCallManager objHappyCallManager = new HappyCallManager();
objHappyCallManager.HappyCallAllocated(Convert.ToInt64(lblOrderID.Text), objWebuser.ShortAbbr, ddlAllocateTo.SelectedValue);
//Update database with person details thats are assigned to the Welcome Call
}
}
}
}
when it goes on to the Foreach gridviewrow etc the count is 1 even though there is 4 rows displaying information ?
Can any one shed any light on this? or even better a solution?
Thank you for your time.
UPdate
<ajaxToolkit:TabPanel ID="tbHappyCall" runat="server" HeaderText="Welcome Calls" TabIndex="10">
<ContentTemplate>
<%--OnRowDataBound="gvConfirmOrder_rowDataBound"--%>
<div id="divHappyCall">
<asp:GridView ID="gvHappyCall" runat="server" AutoGenerateColumns="false" class="tablesorter"
EmptyDataText="There is no Record to display." DataKeyNames="OrderID" EnableViewState="false"
OnRowDataBound="gvHappyCall_RowDataBound">
<AlternatingRowStyle CssClass="NormalTextVNC" BackColor="#E2E9E7"></AlternatingRowStyle>
<Columns>
<asp:TemplateField HeaderText="Account Manager">
<ItemTemplate>
<asp:Label ID="lblAccountManager" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AccountManager") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OrderID">
<ItemTemplate>
<asp:HyperLink ID="hyperOrderID" runat="server" ForeColor="White" NavigateUrl='<%#Eval("OrderGuid","/Documents/HappyCall.aspx?OrderID={0}") %>'
Text='<%#Eval("OrderID") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<ItemTemplate>
<asp:Label ID="lblCustomerName" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CustomerName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Company Name">
<ItemTemplate>
<asp:Label ID="lblCompanyName" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CompanyName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile Number">
<ItemTemplate>
<asp:Label ID="lblMobileNumber" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.MobileNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dispatch Date">
<ItemTemplate>
<asp:Label ID="lblConnectionDate" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DespatchDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField headertext="Date Called" dataformatstring="{0:dd/MM/yyyy}" datafield="EditedDate" HeaderStyle-Width="100px" />
<asp:TemplateField HeaderText="Allocated To">
<ItemTemplate>
<asp:Label ID="lblAllocatedTo" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AllocatedTo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:TemplateField HeaderText="Last Action">
<ItemTemplate>
<asp:Label ID="lblLAstAction" CssClass="gvItem" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LastAction") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="Check">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkAssignWelcomeCall" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:DropDownList runat="server" ID="ddlAllocateTo" CssClass="floatright">
<asp:ListItem>Name of Admin to Allocate</asp:ListItem>
</asp:DropDownList>
<div class="WhiteSpace"></div>
<asp:Button runat="server" ID="btnAllocate" class="floatright" Text="Allocate" OnClick="btnAllocate_click" />
</div>
</ContentTemplate>
</ajaxToolkit:TabPanel>
For clarification: you don't need to iterate the control collection of your TabPanel to find your GridView, it is available directly and don't confuse it's Controls.Count with the number of GridView.Rows.Count.
Is ViewState disabled somewhere?
Edit: I see that the GridView's ViewState is disabled. I assume that it works when you enable it.
I have problem dealing with EditItemTemplate.
What I am trying to do is to update my TextBox txt_name but I can't get what the user ingresses And I get the old value instead at the code-behind.
Am I missing something?
FRONT CODE
<asp:GridView ID="GridView_account" runat="server" AutoGenerateColumns="false" ShowFooter="True"
OnRowCancelingEdit="GridView_account_RowCancelingEdit" OnRowEditing="GridView_account_RowEditing"
OnRowUpdating="GridView_account_RowUpdating" OnRowCommand="GridView_account_RowCommand"
OnRowDeleting="GridView_account_RowDeleting" OnSelectedIndexChanged="GridView_account_SelectedIndexChanged"
DataKeyNames="UID" Height="110px" Width="497px">
<Columns>
<asp:TemplateField HeaderText="UID" SortExpression="UID">
<ItemTemplate>
<asp:Label ID="label_accid" runat="server" Text='<%# Bind("UID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User Name (required)" SortExpression="NyA">
<EditItemTemplate>
<asp:TextBox ID="txt_name" runat="server" Text='<%# Bind("NyA") %>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txt_newname" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="label_name" runat="server" Text='<%# Bind("NyA") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email Address (required)" SortExpression="eMail">
<EditItemTemplate>
<asp:TextBox ID="txt_email" runat="server" Text='<%# Bind("eMail") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txt_newemail" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="label_email" runat="server" Text='<%# Bind("eMail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Options" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton_update" runat="server" CausesValidation="True" CommandName="Update"
Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton_cancel" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel"></asp:LinkButton>
<asp:LinkButton ID="LinkButton_delete" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButton_addnew" runat="server" CausesValidation="False" CommandName="AddNew"
Text="Add New"></asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton_edit" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Manage Role" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="Selectbtn" runat="server" CausesValidation="False" CommandName="Select"
Text="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CODE BEHIND
protected void GridView_account_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
user u = Business.GetUser(((Label)GridView_account.Rows[e.RowIndex].FindControl("label_accid")).Text);
//HERE'S MY PROBLEM!
u.fullname = ((TextBox)GridView_account.Rows[e.RowIndex].FindControl("txt_name")).Text;
//txt_name is returning the old value and not the one the user has input recently.
Business.UpdateUser(u);
GridView_account.EditIndex = -1;
fillgridview();
}//
Are you checking if Page IsPostback when binding your grid? You need to not rebind it in the Page_Load if it is a post back, or else you will lose the new values, because the Page Init, Page Load events happen before other events, such as a Grid Updating event.
May be you are binding you grid on every page_load event. If so, you need something like this:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
GridView_account.DataSource = "data source";
GridView_account.DataBind();
}
}
or instead of
if(!Page.IsPostBack)
you can use
if (GridView_account.EditIndex == -1)
this checks, if grid is in edit mode. If grid is not in edit mode, you can bind your grid with data source.
Im working on the front end development for a website built in .net, This is the first time I've done this and I'm having trouble trying to alter a table.
The code which outputs my table is...
<asp:GridView ID="GV_Concepts" runat="server" AutoGenerateColumns="False" DataKeyNames="ConCatID"
BorderStyle="None" GridLines="None" ShowHeader="False" BorderWidth="0px" CssClass="DashBoard_Concepts">
<Columns>
<asp:TemplateField HeaderText="Catalog">
<ItemTemplate>
<asp:Label ID="LB_Cata" runat="server" Text='<%# Bind("ConCatalog") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle CssClass="col-b" />
</asp:TemplateField>
<asp:TemplateField HeaderText=" Concept Version" ItemStyle-Width="" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<div class="conceptstd">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" BorderStyle="None"
DataSource='<%# Bind("DS_Version")%>'>
<ItemTemplate>
<asp:HyperLink ID="HL_ConcLoc" runat="Server" CssClass="linkage" NavigateUrl='<%# Bind("FileName") %>'
Target="_blank" Text='<%# Bind("Ver") %>'></asp:HyperLink>
<asp:LinkButton ID="LB_remove" runat="server" CommandArgument='<%# Bind("ConceptID") %>'
OnClick="LB_removecon_Click" CssClass="link-btn">Remove</asp:LinkButton>
<asp:LinkButton ID="LB_sign" runat="server" CommandArgument='<%# Bind("ConceptID") %>'
OnClick="LB_signcon_Click" CssClass="sign-off-btn" Visible='<%# SignedCheck(DataBinder.Eval(Container.DataItem,"SignOff")) ?true:false %>'>Sign Off</asp:LinkButton>
<asp:Literal ID="Lit_SignedCon" Visible='<%# SignedCheck(DataBinder.Eval(Container.DataItem,"SignOff")) ?false:true %>'
runat="server"><b>Signed Off</b></asp:Literal>
</ItemTemplate>
</asp:DataList>
</div>
</ItemTemplate>
<HeaderStyle CssClass="col-c" />
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
Currently no concepts
</EmptyDataTemplate>
</asp:GridView>
The html equivalent of this is something similar too...
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
However I need 5 columns not 2, I've tried reading up on the syntax but thought I'd ask here also, Thanks for any help.
I'm not exactly sure how your dataset is structured, but do you need that datalist in there or can you just put the controls in their own ItemTemplate in the GridView? This would give you 5 columns:
<asp:GridView ID="GV_Concepts" runat="server" AutoGenerateColumns="False" DataKeyNames="ConCatID"
BorderStyle="None" GridLines="None" ShowHeader="False" BorderWidth="0px" CssClass="DashBoard_Concepts">
<Columns>
<asp:TemplateField HeaderText="Catalog">
<ItemTemplate>
<asp:Label ID="LB_Cata" runat="server" Text='<%# Bind("ConCatalog") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HL_ConcLoc" runat="Server" CssClass="linkage" NavigateUrl='<%# Bind("FileName") %>'
Target="_blank" Text='<%# Bind("Ver") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LB_remove" runat="server" CommandArgument='<%# Bind("ConceptID") %>'
OnClick="LB_removecon_Click" CssClass="link-btn">Remove</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LB_sign" runat="server" CommandArgument='<%# Bind("ConceptID") %>'
OnClick="LB_signcon_Click" CssClass="sign-off-btn" Visible='<%# SignedCheck(DataBinder.Eval(Container.DataItem,"SignOff")) ?true:false %>'>Sign Off</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal ID="Lit_SignedCon" Visible='<%# SignedCheck(DataBinder.Eval(Container.DataItem,"SignOff")) ?false:true %>'
runat="server"><b>Signed Off</b></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
Currently no concepts
</EmptyDataTemplate>
</asp:GridView>
Of course, this ruins your binding to your datasource, but I'm not sure if I can accurately help you with fixing that :(
the number of column is automatically generated according to asp:templatefield
when you have two templatefield, the only two column will be generated, and the number
of rows depend on data.
so if you need 5 columns you have to put 5 templatefield inside the girdiview
Why do you "need" 5 columns? For layout? Perhaps a GridView isn't the right solution given what you're trying to accomplish. Could a Repeater that generates your content accomplish the same thing?