I'm using a gridview in asp.net. The gridview display heading is too large when it has one row.
But if it has pagination, it displays heading normally. I don't have any idea why.
Any help would be appreciated.
<asp:Panel ID="Panel2" runat="server" Height="310px" Width="100%" CssClass="mPanel" BorderStyle ="Groove">
<asp:GridView ID="gridViewResults" runat="server" Width = "100%"
AllowPaging = "true" OnPageIndexChanging="gridViewResults_PageIndexChanging"
CssClass="mGrid" OnSelectedIndexChanged="gridViewResults_SelectedIndexChanged"
Height="300px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" OnCheckedChanged="chkSelect_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
this is my code and iam binding it thru databasee..
First try this
<HeaderStyle Width="10%" />
<RowStyle Width="10%" />
If not work than do it from code side for all your colums after binding the gridview
int cou = gdv.Columns.Count;
for (int i = 0; i < cou; i++)
{
gdvProReq.Columns[i].HeaderStyle.Width = 50;
gdvProReq.Columns[i].ItemStyle.Width = 50;
}
The GridView will by default automatically size its columns to fit the largest row... when you paginate, the large row that was stretching out the headers was probably moved to one of the later pages.
You can manually size the columns to avoid the headers from dynamically resizing:
<Columns>
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="5%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="25%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="30%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="25%" />
<asp:BoundField DataField="" HeaderText="" ItemStyle-Width="10%" />
</Columns>
Related
I'm working with asp.net nested gridview,in which I need to show the gridview cell values to the textbox for editing.
My problem is that I don't know how to display values to textbox if i ve used both template field & boundfield. Here is my aspx.
<Columns>
<asp:TemplateField ItemStyle-Width="10px">
<ItemTemplate>
<img alt = "" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnsections" runat="server" Style="display: none;">
<asp:HiddenField ID="HdnId" runat="server" Value='<%# Eval("Dept_Name") %>' />
<asp:GridView ID="gvsections" Width="100%" CssClass="table table-bordered table-hover" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvsections_rowdatabound" OnRowEditing="gvsections_rowediting" DataKeyNames="Dept_Name">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="currdept" HeaderText="Deptcurrent" />
<asp:BoundField ItemStyle-Width="150px" DataField="Dept_Name" HeaderText="SectionName" />
<asp:BoundField ItemStyle-Width="150px" DataField="FLDTYPE" HeaderText="Type" HeaderStyle-CssClass=" visible-lg visible-md" ItemStyle-CssClass=" visible-lg visible-md " />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="Dept_Name" HeaderText="Department" />
<asp:BoundField ItemStyle-Width="150px" DataField="FLDTYPE" HeaderText="Type" />
</Columns>
</asp:GridView>
if you are writing the code in selectedindexchanging event of the grid view then try this and it will work
GridViewRow row = gvdepts.Rows[e.NewSelectedIndex];
deptname.Text=row.Cells[1].Text;
I hope this helps
In your code 3 fields contain dept name -- HdnId(Hiddenfield),inner gridview bound field (Dept_Name),Outer gridview bound field(Dept_Name).
1. deptname.Text = (gvdepts.SelectedRow.Cells[1].FindControl("HdnId") as HiddenField).Value;
2. deptname.Text = (gvdepts.SelectedRow.Cells[1].FindControl("gvsections") as GridView).Rows[0].Cells[2].Text;
3. deptname.Text = gvdepts.SelectedRow.Cells[2].Text;
may this link solve your problem:
http://www.aspforums.net/Threads/133072/Edit-Update-Delete-in-Nested-Child-GridView-in-ASPNet/
I have a grid on my aspx page.I have set its font property to small..
On page load it is all okay..
but once I perform some action like a delete activity given in the grid itself..and the grid is bound again by recalling the method to bind grid..
the grid seems to be bigger with big fonts.
What could be the trouble?
<asp:GridView ID="grdSMEList" runat="server" Width="100%" BorderWidth="1px" BorderStyle="Solid"
Font-Size="Small" AutoGenerateColumns="False" BorderColor="#ffcc00" RowStyle-BorderColor="#ffcc00"
AllowPaging="true" PageSize="10" OnPageIndexChanging="GrdDynamic_PageIndexChanging"
DataKeyNames="Resource Personnel No" OnRowCommand="GrdDynamic_RowCommand" RowStyle-BorderStyle="Solid"
RowStyle-BorderWidth="1px" GridLines="Both" Height="104px">
<PagerSettings NextPageText=">>" PageButtonCount="5" PreviousPageText="<<"
FirstPageText="" LastPageText="" Mode="Numeric" />
<PagerStyle HorizontalAlign="Right" Font-Size="Medium" />
<Columns>
<asp:BoundField DataField="Resource Personnel No" HeaderText="Resource Personnel No" ItemStyle-Width="100px" />
<asp:BoundField DataField="RES Name" HeaderText="ResourceName" ItemStyle-Width="100px" />
<asp:TemplateField HeaderText="Deactivate" >
<ItemTemplate>
<div style="text-align:center;">
<asp:LinkButton ID="linkDeactivate" CommandName="cmdDeactivate" OnRowCommand="GrdDynamic_RowCommand"
CommandArgument='<%# Eval("Resource Personnel No") %>' OnClientClick="return confirm('Are you sure you want to Deactivate?');"
runat="server">Deactivate</asp:LinkButton>
</div>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="2%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Did you try specifying the font color in ItemTemplate ? Its worth a try.
I have a gridview in my asp.net page that has one template field for editing a yearly budget. The code follows:
<Columns>
<asp:BoundField DataField="f_year" HeaderText="Year" ReadOnly="True" `enter code here`>
<ItemStyle Width="35px" />
</asp:BoundField>
<asp:BoundField DataField="o_orgcode" HeaderText="Cost Center " ReadOnly="True" />
<asp:BoundField DataField="o_orgdesc" HeaderText="CostCenterDesc " ReadOnly="True" />
<asp:BoundField DataField="s_subobject" HeaderText="Account " ReadOnly="True" />
<asp:BoundField DataField="s_subdescrip" HeaderText="AccountDesc" ReadOnly="True" />
<asp:TemplateField HeaderText="Initial Appropriation">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text="$"></asp:Label>
<asp:TextBox ID="txtEditItemApprAmt" runat="server" Text='<%# Bind("b_budgetamt", "{0:f}") %>' CssClass="boxright"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="txtEditItemApprAmt2" runat="server" Text='<%# Bind("b_budgetamt", "{0:f}") %>' CssClass="boxright"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:BoundField DataField="b_initials" ReadOnly="True" >
<ItemStyle Width="35px" />
</asp:BoundField>
When my page loads the one template I field I have will automatically appear as a databound text box. I do this because there are multiple money figures to enter at one time and I believe this to be a better function for me site. I want to be able to click an external (meaning external to the gridview) button to loop through the gridview and change those values in my database. Anyone know how to do this, I have not been able to find on the internet an example of this?? Thanks!
You can do it this way,
foreach(GridVieRrow row in gv.rows)
{
TextBox txtEditItemApprAmt = row.FindControl("txtEditItemApprAmt");
string ApprAmt = txtEditItemApprAmt.Text;
txtEditItemApprAmt.Text = someTextFunctionOrVariable;
}
I'm trying to reduce the overall height of this gridview so there aren't so many "empty rows" at the bottom. I tried setting the Height attribute. I also tried setting the PagingSize to a smaller number and setting the AllowPaging Attribute=true
The datasource will return a variable number of rows, but the gridview needs to be fixed height. Right now it's taking up a lot more vertical real estate than any max number of HearingInfo would even reach. In other words, there is enough space at the bottom for at least 10 more rows, but there would never ever be 10 more rows.
I haven't worked with ASP.net web controls in a while...
<asp:GridView ID="gvHearingInfo" runat="server" AutoGenerateColumns="False" EnableModelValidation="True"
ShowHeader="False" Width="100%" GridLines="Vertical"
Height="50px">
<Columns>
<asp:BoundField DataField="Authority" HeaderText="Authority"
SortExpression="Authority">
<ItemStyle Width="144px" Wrap="False" HorizontalAlign="Left"
BorderColor="Black" />
</asp:BoundField>
<asp:BoundField DataField="PublicHearing" HeaderText="PublicHearing"
SortExpression="PublicHearing" >
<ItemStyle HorizontalAlign="Left" Width="431px" BorderColor="Black" />
</asp:BoundField>
<asp:BoundField DataField="HearingDate" HeaderText="HearingDate"
SortExpression="HearingDate" >
<ItemStyle HorizontalAlign="Center" Width="93px" BorderColor="Black" />
</asp:BoundField>
<asp:BoundField DataField="HearingTime" HeaderText="HearingTime"
SortExpression="HearingTime" >
<ItemStyle HorizontalAlign="Center" Width="92px" BorderColor="Black" />
</asp:BoundField>
<asp:BoundField DataField="DistrictTelephone" HeaderText="DistrictTelephone"
SortExpression="DistrictTelephone" >
<ItemStyle HorizontalAlign="Center" Width="94px" BorderColor="Black" />
</asp:BoundField>
</Columns>
</asp:GridView>
Results.DataSource = dataView;
Results.DataBind();
foreach(GridViewRow row in this.Results.Rows)
{
if (row.Equals(""))
{
Results.Rows[0].Visible = false;
}
}
or you will have to use the GridView.RowDataBound Event but I think the code should do the work...
I am really frustrated to find a solution for my scenario. I have two gird when First grid is used show the shop information and the second grid is used to edit the offers related to the shop information. When the users edit the second grid i will just update the text box values related to the grid selection row. in my code behind file i can see the data fetching from the grid and assigning into the text boxes but when the function call (imgEdit_click) finished the page does not show the values. Editing functionality can be done in many ways but my scenario is what i explained earlier . I have the checked page there is no Postback action has been called after the method I could not find the solution can anyone help me to figure it out.
Following are my source and code behind codes.
My design Source :
<div class="field">
<asp:TextBox ID="txtareaOfferDesc" runat="server" TextMode="MultiLine" ></asp:TextBox>
</div>
<div class="field">
<asp:TextBox ID="txtTimeStarts" runat="server" CssClass="textfield"></asp:TextBox>
<cc1:CalendarExtender
ID="CalendarExtender2"
runat="server"
TargetControlID="txtTimeStarts"
CssClass="CalendarCSS">
</cc1:CalendarExtender>
<div class="datefld">
<label class="name">Offer end date/time (optional)</label>
<div class="field">
<asp:TextBox ID="txtTimeEnd" runat="server" CssClass="textfield"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender4" runat="server" TargetControlID="txtTimeEnd"
CssClass="CalendarCSS">
</cc1:CalendarExtender> `
<asp:GridView ID="gvShopDeal" runat="server" AutoGenerateColumns="false"
CssClass="tblexistoffer" DataKeyNames="ShopID" AllowPaging="True"
AllowSorting="True">
<Columns>
<asp:TemplateField>
<HeaderTemplate >
<asp:CheckBox ID="chkHeader" runat="server" />
<asp:Label ID="lblSelectAll" Text="Select All" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate >
<asp:CheckBox ID="chkRow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ShopID" HeaderStyle-Width="10%" HeaderText="Shop ID" />
<asp:BoundField DataField="ShopName" HeaderStyle-Width="40%" HeaderText="Shop Name" />
<asp:BoundField DataField="Street" HeaderStyle-Width="40%" HeaderText="Street" />
<asp:BoundField DataField="City" HeaderText ="City" />
</Columns>
</asp:GridView>
<asp:Button ID="btnCreateDeal" runat="server" Text="Create Offer"
CssClass="grnbtn" OnClientClick="return CheckDealValidation(this)" onclick="btnCreateDeal_Click"></asp:Button>
<asp:Button ID="btnDefCancel" runat="server" Text="Cancel" CssClass="greybtn"></asp:Button>
<asp:UpdatePanel ID="UpdateExistingOffer" runat="server">
<ContentTemplate>
<asp:GridView ID="gvExistingOffers" runat="server" CssClass="tblexistoffer"
AutoGenerateColumns="false" DataKeyNames="OfferID" AllowPaging="True"
AllowSorting="True">
<Columns>
<asp:BoundField DataField="OfferID" HeaderText="OfferID" />
<asp:BoundField DataField="Description" HeaderText="OfferName" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="OfferType" HeaderText="OfferType" />
<asp:BoundField DataField="StartDate" HeaderText="StartDate">
<ItemStyle CssClass="Hide" />
<HeaderStyle CssClass="Hide" />
</asp:BoundField>
<asp:BoundField DataField="EndDate" HeaderText="EndDate" >
<ItemStyle CssClass="Hide" />
<HeaderStyle CssClass="Hide" />
</asp:BoundField>
<asp:TemplateField HeaderText="Edit" HeaderStyle-Width="5%">
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" ImageUrl="~/Merchant/images/edit.jpg" runat="server" Width="25" Height="25" onclick="imgbtnEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind File :
protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
fferIDForShop = Convert.ToInt32(gvExistingOffers.DataKeys[gvrow.RowIndex].Value);
ShopList objShopID = ShopService.GetShopID(OfferIDForShop);
(txtareaOfferDesc.Text) = gvrow.Cells[1].Text.Trim();
txtTimeStarts.Text = gvrow.Cells[4].Text;
txtTimeEnd.Text = gvrow.Cells[5].Text;
}
Thanks
Vijay
Issue is because textboxes are out of Update Panel, So just put everything in update panel it will start functioning or just comment out update panel and then try the same thing.