how to adjust width of gridview items - c#

how can i change the width of the gridview items? i tried adding itemstyle-width but it doesnt change anything. is it because my gridview is too crowded and does not fit into my screen or something is wrong with my codes?
<asp:GridView ID="gvModal" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" EmptyDataText="No Records" AllowPaging="true" CellPadding="4" HeaderStyle-BackColor="CornflowerBlue" BorderWidth="2" BorderColor="CornflowerBlue" Width="100%" CssClass="table table-hover" >
<Columns>
<asp:TemplateField HeaderText ="ID" HeaderStyle-ForeColor="White">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#Bind ("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Type" HeaderStyle-Width="230px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri" >
<ItemTemplate>
<asp:Label ID="lbltype" runat="server" Text='<%#Bind ("ItemType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Model" HeaderStyle-Width="240px" ItemStyle-Width="300px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblModel" runat="server" Text='<%# Bind("ItemModel") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Requested Quantity" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblQuan" runat="server" Text='<%#Bind ("ItemQuantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="AMS Balance" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblAMS" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Incoming Stock" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblIncoming" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Unit" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblUnit" runat="server" Text='<%#Bind ("ItemUnit") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Date Needed" HeaderStyle-Width="180px" ItemStyle-Width="150px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%#Bind ("ItemDate" , "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Description" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%#Bind ("ItemDesc") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Status" ItemStyle-Width="120px" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%#Bind ("ItemStatus") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="PO Number" HeaderStyle-ForeColor="White" ItemStyle-Width="120px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblPONumber2" runat="server" Text='<%#Bind ("PO_Num") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="PO Date" HeaderStyle-ForeColor="White" ItemStyle-Width="150px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblPODate2" runat="server" Text='<%#Bind ("PO_Date", "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Delivery Date" HeaderStyle-ForeColor="White" ItemStyle-Width="150px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblDelDate2" runat="server" Text='<%#Bind ("Delivery_Date", "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Issuance Date" HeaderStyle-ForeColor="White" ItemStyle-Width="180px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblIssDate2" runat="server" Text='<%#Bind ("IssuanceDate", "{0:yyyy-MM-dd}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Issuance Number" HeaderStyle-ForeColor="White" ItemStyle-Width="110px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
<ItemTemplate>
<asp:Label ID="lblIssNum2" runat="server" Text='<%#Bind ("IssuanceNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Issuance" ItemStyle-Font-Names="Calibri" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Width="170px">
<ItemTemplate>
<asp:Label ID ="lblIssued" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Font-Names="Calibri" ItemStyle-Width="80px">
<ItemTemplate>
<asp:Label ID ="lblQuantity" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Font-Names="Calibri" ItemStyle-Width="80px">
<ItemTemplate>
<asp:Label ID ="lblUnits" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

The width is specified as 100% in the gridview bit in the columns , you are using px to denote the widths, Either change the width to the actual width(in pixels),and then ensure the sum of all the template fields and bound fields are equal, or change the template field widths to percentages and ensure it totals to 100.

Consider that total width of your Grid view is 100% then you can assign proportional percentages to each columns(Please note, Sum of percentages of the TemplateField will not exceed 100). Another thing have to be noticed is, you have to set both HeaderStyle-Width and ItemStyle-Width while setting the width of the column. For example:
<asp:TemplateField HeaderText ="ID" HeaderStyle-ForeColor="White" HeaderStyle-Width="10%" ItemStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text=" ID" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
By doing like this you are setting the width of the ID column to 10% of the actual width of the Grid

The BoundField displays all content in a table cell and therefore the cell will expand as needed. The TemplateField will also be rendered as a cell BUT it contains a div which limits the width of any contents.
Example with code

Related

How can I add static text as Footer at the bottom of the GridView?

I am trying to add a Foot Note at the bottom of the Grid. but from the below code snippet, I am seeing footnote at the bottom but it is coming in the empty columns. I mean to say if I have 4 columns in the Grid, the Foot Note is displaying after the 4th column. this should not happen. Ideally, the footnote will starts from the first column until the end of the grid. (as a row)
Any suggestions, please?
<asp:Table ID="Table1" BorderWidth="0" CellPadding="0" CellSpacing="0" Width="100%" runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:GridView ID="_gridView1" runat="server"
EnableViewState="false" ShowFooter="true" AllowPaging="false" EnableFixedHeader="true" Width="100%"
AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="12%" ItemStyle-Width="12%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate >
<asp:Label ID="_LineName" runat="server" Text='<%# Eval("LineName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity0" HeaderText="Entity0" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
<ItemTemplate>
<asp:Label ID="_entityZero" runat="server" Text='<%# Eval("EntityName0") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity1" HeaderText="Entity1" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityOne" runat="server" Text='<%# Eval("EntityName1") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity2" HeaderText="Entity2" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityTwo" runat="server" Text='<%# Eval("EntityName2") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity3" HeaderText="Entity3" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityThree" runat="server" Text='<%# Eval("EntityName3") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity4" HeaderText="Entity4" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityFour" runat="server" Text='<%# Eval("EntityName4") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity5" HeaderText="Entity5" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityFive" runat="server" Text='<%# Eval("EntityName5") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity6" HeaderText="Entity6" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entitySix" runat="server" Text='<%# Eval("EntityName6") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity7" HeaderText="Entity7" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entitySeven" runat="server" Text='<%# Eval("EntityName7") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity8" HeaderText="Entity8" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityEight" runat="server" Text='<%# Eval("EntityName8") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity9" HeaderText="Entity9" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityNine" runat="server" Text='<%# Eval("EntityName9") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="Entity10" HeaderText="Entity10" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="8%">
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top"/>
<ItemTemplate>
<asp:Label ID="_entityTen" runat="server" Text='<%# Eval("EntityName10") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ID="footer" HeaderStyle-HorizontalAlign="Left">
<FooterTemplate>
<asp:Label id="lblFooter" runat="server">'Last Review Date' indicates the date on which an Issuer Rating was last formally reviewed within a twelve-month period or when a Credit Rating Action was last published. <br /></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:TableCell>
</asp:TableRow>
</asp:Table>

Export Nested Gridview into Excel

I have the following UI design for a nested GridView. According to that I want a solution for exporting a nested Gridview into Excel.
Nested GridView
<asp:GridView ID="Mastergrid" PageSize="20" AllowPaging="true" Width="100%" Height="100%" OnPageIndexChanging="Mastergrid_PageIndexChanging" runat="server" AutoGenerateColumns="false" CssClass="gridview" DataKeyNames="r_id" OnRowDataBound="Mastergrid_RowDataBound" ShowHeaderWhenEmpty="true">
<Columns>
<asp:TemplateField HeaderText="id" Visible="false">
<ItemTemplate>
<asp:Label ID="lblr_id" runat="server" Text='<%# Eval("r_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reg. No">
<ItemTemplate>
<asp:Label ID="lblregid" runat="server" Text='<%# Eval("r_uid") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Indos No.">
<ItemTemplate>
<asp:Label ID="lblindosno" runat="server" Text='<%# Eval("indos_no") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Infomation">
<ItemTemplate>
<asp:GridView ID="subgrid" ShowHeader="true" runat="server" AutoGenerateColumns="false" Width="100%" Height="100%" EmptyDataText="No Record found..!!" CssClass="gridview1">
<Columns>
<asp:TemplateField HeaderText="Course id" Visible="false" HeaderStyle-Width="5%" >
<ItemTemplate>
<asp:Label ID="Course_id" runat="server" Text='<%# Eval("Course_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Name" HeaderStyle-Width="60%">
<ItemTemplate>
<asp:Label ID="lblcoursename" runat="server" Text='<%# Eval("course_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Fees" >
<ItemTemplate>
<asp:Label ID="lblcoursefees" runat="server" Text='<%# Eval("course_fees") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Course Date">
<ItemTemplate>
<asp:Label ID="lblcoursedate" runat="server" Text='<%# Eval("course_date","{0:dd-MM-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You need to find the nested grid with FindControl:
protected void Mastergrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "exportNestedGrid")
{
//convert the CommandArgument
int rowNumber = Convert.ToInt32(e.CommandArgument);
//find the nested GridView
GridView gridview = GridView1.Rows[rowNumber].FindControl("subgrid") as GridView;
//do stuff with the nested GridView
gridview.Visible = false;
}
}
And for getting the rowNumber, you could send it along with the export button:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" CommandArgument='<%# Container.DataItemIndex %>' CommandName="exportNestedGrid" runat="server" Text="Export nested GridView" />
</ItemTemplate>
</asp:TemplateField>
we can export Nested Gridview same as simple gridview into the excel.

How to hide and show column in gridview

I have written below lines of code in order to hide and show column in gridview based on the condition.
<asp:TemplateField HeaderText="FirstName" Visible='<%# Eval("FirstName") != null ? true:false %>'>
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
It's not working!
Update in code as below :
<asp:TemplateField HeaderText="FirstName" Visible='<%= !string.IsNullOrEmpty(Eval("FirstName")) ? "true" : "false" %>'>
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Edit
<asp:TemplateField HeaderText="FirstName" Visible='<%# !string.IsNullOrEmpty(Eval("FirstName")) ? "true" : "false" %>'>
<ItemTemplate>
<asp:Label ID="lblFirstName" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Grid View
<asp:GridView ID="GridDisplay" runat="server" AutoGenerateColumns="False" BorderStyle="Groove"
BorderWidth="1px" BorderColor="ActiveCaptionText" Width="100%" EmptyDataText="No Record Found"
AllowPaging="True" OnPageIndexChanging="GridDisplay_PageIndexChanging" AllowSorting="True"
OnRowEditing="GridDisplay_RowEditing" OnRowDeleting="GridDisplay_RowDeleting"
CssClass="listbooking ListingTable">
<Columns>
<asp:TemplateField HeaderText="Booking Code">
<ItemTemplate>
<%# Eval("id")%>
</ItemTemplate>
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Property Code">
<ItemTemplate>
<%# Eval("property_id")%>
</ItemTemplate>
<HeaderStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# Eval("sales_username")%>
</ItemTemplate>
<HeaderStyle Width="18%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
i am trying to hide 2 columns(name).
During Binding the grid data
this.GridDisplay.Columns[2].Visible = false;

how to show edit and delete button at the right side of a gridview not at left in asp.net?

i want edit and delete button on the right side of the gridview not
at left side of grid. for user friendly manipulation of gridview.
how to show buttons at right side of my grid view?
<asp:GridView ID="GvAllTasks" runat="server" AutoGenerateColumns="false"
AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
CssClass="table table-hover table-bordered"
onrowcancelingedit="GvAllTasks_RowCancelingEdit"
onrowdeleting="GvAllTasks_RowDeleting"
onrowediting="GvAllTasks_RowEditing" onrowupdating="GvAllTasks_RowUpdating" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found">
you need to set AutoGenerateColumns property false and create the required columns for the grid using property within the html source of the grid in whatever order you want. The columns can be pre defined columns like CheckBoxField, ImageField etc. or templatecolumns. The following example shows creating a grid with edit and delete buttons on right for a table with name DEPT having three columns DEPTNO, DNAME and LOC.
<asp:GridView ID="GvDept" runat="server" AutoGenerateColumns="False"
ShowFooter="true"style="z-index: 1; left: 145px; top: 22px;position:
absolute; height: 191px; width: 756px;font-family: 'Arial Black';
font-size: large" EnableViewState="False">
<Columns>
<asp:TemplateField HeaderText="Deptno">
<ItemTemplate>
<asp:Label ID="LblDno" runat="server"
Text='<%# Eval("Deptno") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dept Name">
<ItemTemplate>
<asp:Label ID="LblDname" runat="server"
Text='<%# Eval("Dname") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location">
<ItemTemplate>
<asp:Label ID="LblLoc" runat="server"
Text='<%# Eval("Loc") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="LnkEdit" runat="server" Text="Edit"
CommandName="Edit" />
<asp:LinkButton ID="LnkDelete" runat="server"
Text="Delete" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
for adding edit and delete buttons left side of ur gridview add
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
in your columns after your template field
CssClass="table table-hover table-bordered"
onrowcancelingedit="GvAllTasks_RowCancelingEdit"
onrowdeleting="GvAllTasks_RowDeleting"
onrowediting="GvAllTasks_RowEditing" onrowupdating="GvAllTasks_RowUpdating" ShowHeaderWhenEmpty="True" EmptyDataText="No records Found">
<%-- AutoGenerateEditButton="true"--%>
<%-- AutoGenerateDeleteButton="true" --%>
<Columns>
<asp:TemplateField HeaderText="Task Id">
<ItemTemplate>
<asp:HiddenField ID="HiddTaskid" runat="server" Value='<%# Eval("task_Id") %>' />
<%#Eval("task_Id")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Name">
<ItemTemplate>
<%#Eval("task_Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assigned To">
<ItemTemplate>
<%#Eval("task_Employee_Name")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Project Name">
<ItemTemplate>
<%#Eval("task_Project_Title")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Status">
<ItemTemplate>
<%#Eval("task_Status")%>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lbl_Status" runat="server" Text='<%#"Status : " + Eval("task_Status") %>'></asp:Label>
<asp:DropDownList ID="Gv_DdlStatus" runat="server">
<asp:ListItem Text="-Change Status-" Value="0"></asp:ListItem>
<asp:ListItem Text="Reviewed" Value="1"></asp:ListItem>
<asp:ListItem Text="InProgress" Value="1"></asp:ListItem>
<asp:ListItem Text="Completed" Value="2"></asp:ListItem>
<asp:ListItem Text="Stopped" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:HiddenField ID="hiddstatusId" runat="server" Value='<%# Eval("task_Status") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Start dt">
<ItemTemplate>
<%#Eval("task_StartDate")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task Completed dt">
<ItemTemplate>
<%#Eval("TaskCompletedDt")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtTaskCompletedDt" runat="server" Text='<%# Eval("TaskCompletedDt") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assigned By">
<ItemTemplate>
<%#Eval("AssignedBy")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Comments">
<ItemTemplate>
<%#Eval("comment")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtComments" runat="server" Text='<%# Eval("comment") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>

How do I get values from Templates in a datagrid row for a query string?

I have two Template fields in a datagrid whose values I need to pass in a query string in a Hyperlink field in the datagrid.
The first value I need is the Nest Number. The second is the Park Name.
How do I put those values in the querystring?
Here is the start of the gridview with the two Templates:
<asp:GridView ID="NestListGrid" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" Width="95%" OnRowCancelingEdit="NestListGrid_RowCancelingEdit" OnRowEditing="NestListGrid_RowEditing" OnRowUpdating="NestListGrid_RowUpdating" >
<Columns>
<asp:BoundField DataField="NestID" Visible="False" />
<asp:TemplateField HeaderText="Nest Nbr">
<EditItemTemplate>
<asp:TextBox ID="NestNumber_tbx" Width="100px" MaxLength="10" runat="server" Text='<%# Bind("NestNumber") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="NestNumber_lbl" runat="server" Text='<%# Bind("NestNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Park">
<EditItemTemplate>
<asp:DropDownList ID="Park_ddl" runat="server" DataSourceID="ParkIDNameGridViewDDL_SDS"
DataTextField="ParkName" DataValueField="ParkID" SelectedValue='<%# Bind("ParkID") %>' >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ParkName_lbl" runat="server" Text='<%# Bind("ParkName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
...etc...
Here is the Hyperlink Query String later in the datagrid:
<asp:HyperLinkField Text="Nest Info" DataNavigateUrlFields="NestID" DataNavigateUrlFormatString="NestInfoUser.aspx?NestID={0}&NestNumber={0}&ParkName={0}" />
-
You can use with comma.
<asp:HyperLinkField Text="Nest Info" DataNavigateUrlFields="NestID,ParkName"
DataNavigateUrlFormatString="NestInfoUser.aspx?NestNumber={0}&ParkName={1}" />

Categories

Resources