I have a GridView with one nested GridView as follows:
<asp:GridView ID="gvEmpNew" runat="server" AutoGenerateColumns="false" BackColor="White"
BorderColor="#E9ECEF" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" ShowFooter="true"
GridLines="None" EmptyDataText="There are no data records to display." OnRowDataBound="gvEduTrainingExp_RowDataBound"
Width="970px">
<Columns>
<asp:TemplateField ItemStyle-CssClass="gridViewCellCenter" HeaderStyle-CssClass="headerStyle" >
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("empid") %>', 'two');">
<img id="imgdiv<%# Eval("empid") %>" alt="Click to show/hide Details for Education Information <%# Eval("empid") %>"
width="15px" border="0" src="../images/plus.gif" title="Education" />
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="gridViewCellCenter" HeaderStyle-CssClass="headerStyle" >
<ItemTemplate>
<div></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("empid") %>" style="display:none; position: relative;
left: 10px; width: 100%">
<asp:GridView ID="GridViewChildEducation" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#E9ECEF" BorderStyle="None" BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="None" EmptyDataText="">
<Columns>
<asp:TemplateField HeaderText="EXAM TITLE">
<ItemTemplate>
<asp:Label ID="lblEXAM_TITLE" runat="server" Text='<%# Eval("EXAM_TITLE") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EDUCATION LEVE LNAME" >
<ItemTemplate>
<asp:Label ID="lblEDUCATIONLEVELNAMEChild" runat="server" Text='<%# Eval("EDUCATIONLEVELNAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="headerStyle" />
<RowStyle CssClass="rowStyle" />
<AlternatingRowStyle CssClass="alternatingRowStyle" />
</asp:GridView>
</Columns>
<HeaderStyle CssClass="headerStyle" />
<RowStyle CssClass="rowStyle" />
<AlternatingRowStyle CssClass="alternatingRowStyle" />
</asp:GridView>
I want to hide one of the GridView named GridViewChildEducation. I tried this code:
GridViewChildEducation.Columns[1].Visible = false;
It shows me that the name GridViewChildEducation does not exist in the current context. I need a way to hide or show any column of this 'GridViewChildEducation' GridView
Couldn't you use:
GridViewChildEducation.Style.Visibility="hidden";
GridViewChildEducation.Style.Display="none";
or crease a CSS class for hidden and one for visible, and go that route.
I'm a little confused, though - are you only trying to hide one column, or the whole view?
Related
I have a Gridview that has a 3 columns , one of them(ObjectiveID) is invisible using the CSS:
<style type="text/css">
.hidden {
display: none;
}
</style>
But, when i use this style, i got misplaced columns headers as shown in the picture below :
My Aspx code:
<div class="form-group col-md-8">
<asp:GridView runat="server" ID="grdPlanObjectivesStandardWeights" AutoGenerateColumns="False"
CssClass="table table-hover table-bordered table-responsive table-striped"
HeaderStyle-CssClass="tableHeader"
DataKeyNames="ObjectiveID"
EmptyDataText="<%$Resources:DCAACommon, NoDataMessage%>"
EmptyDataRowStyle-CssClass="alert alert-warning"
EmptyDataRowStyle-HorizontalAlign="Center">
<Columns>
<asp:BoundField DataField="ObjectiveID">
<ItemStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="<%$ Resources:DCAAStrategicManagement, Initiative_ObjectiveName %>" />
<asp:TemplateField HeaderText="<%$ Resources:DCAAStrategicManagement, obj_lblStandardWeight %>" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:TextBox runat="server" ID="txtStandardWeight" onkeypress="return onlyNumbers();" Text='<%# Eval("StandardWeight") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pagination-gridView" />
<PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" />
</asp:GridView>
</div>
Note: i need to keep the ObjectiveID invisible, and i must not use Visible="False" to the BoundField.
Any help would be appreaciate.
You are hiding a <td> item, not it's content. This will lead to weird behaviour.
A solution is to change the BoundField to a TemplateField. You'll have more control that way.
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField ItemStyle-CssClass="hidden">
<ItemTemplate>
<span><%# Eval("ObjectiveID") %></span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<style type="text/css">
.hidden span {
display: none;
}
</style>
I was trying to hide only the items , all i needed is to also hide the Header.
So, i have changed this :
<asp:BoundField DataField="ObjectiveID">
<ItemStyle CssClass="hidden" />
</asp:BoundField>
To this:
<asp:BoundField DataField="ObjectiveID" ItemStyle-CssClass="hidden" HeaderStyle-CssClass="hidden"/>
And it worked just fine.
Works fine in google chrome and firefox but GRIDVIEW is not appearing in IE11.
No errors in console, viewed source and it just isnt there??
Had a look online and couldnt find much someone suggested adding in GridLines="None" but that didnt have any effect....Any ideas please?
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false" Width="100%" ViewStateMode="Enabled"
BorderWidth="1px" BackColor="White" CellPadding="3" BorderStyle="None"
BorderColor="#CCCCCC" Font-Names="Arial" GridLines="None">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<PagerStyle ForeColor="#000066" HorizontalAlign="Left"
BackColor="White"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True"
BackColor="#1e4964"></HeaderStyle>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="SelectedCheckBox" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="CheckHeader" OnCheckedChanged="CheckHeader_OnCheckedChanged" AutoPostBack="true" runat="server" />
</HeaderTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="File" DataField="File">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Date Added" DataField="DateAdded" DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<a href="<%# ResolveUrl((string)Eval("LargePictureURL"))%>" onclick="magnificPopup('GridView1')">
<img alt="" src='<%# ResolveUrl((string)Eval("PictureURL"))%>' style="max-height: 20px; max-width: 30px; text-align: center" />
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="ID" DataField="ID" Visible="true">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True"
BackColor="#669999"></SelectedRowStyle>
<RowStyle ForeColor="#000066"></RowStyle>
</asp:GridView>
UPDATE
The gridview is populated with
// Update the images displayed on the gridview
GridView1.DataSource = GetData(false);
GridView1.DataBind();
upViewUploadImages.Update();
Same process shows images for FIREFOX and GOOGLE but not on IE.
The problem is that you don't have set the data source on your grid view - DataSourceID not exist at all.
To display some data your on grid view you need to tell him what that data are.
So I will confuse at first because I believe the the IE11 was the problem but after your comments I realize that you do not have set any data to show !
Eg: You must have something like (if you do not use code behind data binder)
<asp:GridView DataSourceID="ThisPageSql" runat="server" ...
<asp:SqlDataSource ID="ThisPageSql" runat="server"
ConnectionString="<%$ ConnectionStrings:DbCoonect %>" ...
I have the following Gridview. I need sorting arrows in every column header for sorting. I have set AllowSorting property to true.But it is not showing the arrows.Additionally, I added SortExpression to template fields .Still it is not showing the sorting arrows. I couldn't understand the issue. How can I fix this issue?
The code is given below
<asp:GridView ID="dgvCatReport" runat="server"
AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None"
AllowPaging="True"
AllowSorting="true"
OnPageIndexChanging="dgvCatReport_PageIndexChanging"
PagerSettings-Mode="NumericFirstLast"
PagerSettings-Position="TopAndBottom"
PageSize="10"
CssClass=" table table-striped table-hover"
AlternatingRowStyle-CssClass="alt"
PagerStyle-CssClass="bs-pagination">
<columns>
<asp:templatefield headertext="Category Name" sortexpression="CatName">
<itemtemplate>
<h5><%# Eval("CatName") %></h5>
</itemtemplate>
<headerstyle horizontalalign="Left" />
<itemstyle width="200px" />
</asp:templatefield>
<asp:templatefield headertext="Total Views" sortexpression="ReportCount">
<itemtemplate>
<span><%# Eval("ReportCount") %></span>
</itemtemplate>
<headerstyle horizontalalign="Left" />
<itemstyle width="75px" />
</asp:templatefield>
<asp:templatefield headertext="Daily Views" sortexpression="DailyCount">
<itemtemplate>
<span><%# Eval("DailyCount") %></span>
</itemtemplate>
<headerstyle horizontalalign="Left" />
<itemstyle width="75px" />
</asp:templatefield>
<asp:templatefield headertext="Weekly Views" sortexpression="WeeklyCount">
<itemtemplate>
<span><%# Eval("WeeklyCount") %></span>
</itemtemplate>
<headerstyle horizontalalign="Left" />
<itemstyle width="75px" />
</asp:templatefield>
<asp:templatefield headertext="Monthly Views" sortexpression="MonthlyCount">
<itemtemplate>
<span><%# Eval("MonthlyCount") %></span>
</itemtemplate>
<headerstyle horizontalalign="Left" />
<itemstyle width="75px" />
</asp:templatefield>
</columns>
<%-- <pagersettings mode="NumericFirstLast" position="TopAndBottom"></pagersettings>
<pagerstyle backcolor="White" cssclass="pgr"></pagerstyle>--%>
</asp:GridView>
I'm not sure if Asp.net grid provides default images for sorting. But you can still use a custom approach to show images.
set the Gridview properties
SortedAscendingHeaderStyle-CssClass="sortasc"
SortedDescendingHeaderStyle-CssClass="sortdesc"
Add css classes:
th.sortasc a
{
display:block; padding:0 4px 0 15px;
background:url("images/icons/ascArrow.png") no-repeat;
}
th.sortdesc a
{
display:block; padding:0 4px 0 15px;
background:url("images/icons/descArrow.png") no-repeat;
}
I'm a newbie in asp.net development. Any help would be much appreciated. :)
What I need to accomplish is to retain the selected value of my drop down lists in my gridview even when the user navigate to the next page index. I am thinking to put the values into session while page are changing and put it back when the page shows again. I have tried to do this in check box only and I don't know how to implement using drop down lists. I have 4 drop down lists by the way. Please help. Thanks a lot. Below is my code
<asp:GridView ID="gvwAssociation" runat="server" AutoGenerateColumns="False"
AllowSorting="True" HorizontalAlign="Left" AllowPaging="true" Height="75%" Width="100%" SkinID="TitleReviewGridViewSkin"
OnRowDataBound="gvwAssociation_RowDataBound" PageSize="20" OnPageIndexChanging="gvwAssociation_PageIndexChanging" DataKeyNames="ID">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" Visible="true"/>
<asp:BoundField DataField="_fileName" HeaderText="File Name"/>
<asp:BoundField DataField="_uploadDate" HeaderText="Upload Date" DataFormatString="{0:MM-dd-yyyy}" />
<asp:TemplateField HeaderText="Pool">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<%--<asp:dropdownlist ID="ddlPool" runat="server" ReadOnly="false" Width="75px" ForeColor="Black" MaxLength="6" EnableViewState="true"></asp:dropdownlist> --%>
<asp:DropDownList ID="ddlpool" width="75px" runat="server" AutoPostBack="false"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Year">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<%--<asp:dropdownlist ID="ddlyear" runat="server" ReadOnly="false" Width="75px" ForeColor="Black" MaxLength="6" EnableViewState="true"></asp:dropdownlist>--%>
<asp:DropDownList ID="ddlyear" width="75px" runat="server" AutoPostBack="false"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Plant">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<%-- <asp:dropdownlist ID="ddlplant" runat="server" DataTextField='<%# Bind("_plant") %>' DataValueField='<%# Bind("_plant") %>' ReadOnly="false" Width="150px" ForeColor="Black" MaxLength="6" EnableViewState="true" AppendDataBoundItems="true" ></asp:dropdownlist> --%>
<asp:DropDownList ID="ddlplant" width="135px" runat="server" AutoPostBack="false"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Event">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemTemplate>
<%-- <asp:dropdownlist ID="ddlevent" runat="server" DataTextField='<%# Bind("_event") %>' DataValueField='<%# Bind("_plant") %>' ReadOnly="false" Width="150px" ForeColor="Black" MaxLength="6" EnableViewState="true" AppendDataBoundItems="true" ></asp:dropdownlist> --%>
<asp:DropDownList ID="ddlevent" width="135px" runat="server" AutoPostBack="false"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns> </asp:GridView>
Hope you binding a DataTable to GridView.
Save the Data Table which you are binding to the GridView and Update the Same DataTable something like beow.
gvwAssociation_PageIndexChanging(object sender,GridViewPageEventArgs e)
{
DataTable dt = (DataTable)Session["SavedDataTable"];
foreach (GridViewRow gvRow in gvwAssociation.Rows)
{
DropDownList ddlpool = (DropDownList)gvRow.FindControl("ddlpool");
DropDownList ddlyear = (DropDownList)gvRow.FindControl("ddlyear");
if (dt.Select("ID=" + gvRow.Cells[1].Text).Length > 0)
{
dt.Select("ID=" + gvRow.Cells[1].Text)[0]["Pool"] = ddlpool.SelectedValue;
dt.Select("ID=" + gvRow.Cells[1].Text)[0]["Year"] = ddlyear.SelectedValue;
}
}
Session["SavedDataTable"] = dt;
gvwAssociation.PageIndex = e.NewPageIndex;
gvwAssociation.DataSource = dt;
gvwAssociation.DataBind();
}
I have the following grid:
<asp:GridView ID="myGrid"
AutoGenerateColumns="true"
runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%">
<AlternatingRowStyle CssClass="rowEven" />
<HeaderStyle CssClass="rowHead" />
<RowStyle CssClass="row" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" data-flag="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and its generating
<span data-flag="false"><input id="ctl00_PlaceHolderMain_myGrid_ctl02_CheckBox1" type="checkbox" name="ctl00$PlaceHolderMain$myGrid$ctl02$CheckBox1" /></span>
I want the data flag inside the checkbox. not as an span
Possible and simple workaround is to use the simple html checkbox with a runat="server"
<ItemTemplate>
<input id="Checkbox1" runat="server" type="checkbox" data-flag="false" />
</ItemTemplate>
I think you should use Checked="false" instead of data-flag.