Programmatically Set Alignment Of Databound GridView?
Mar 23, 2011
Here is my code:
GridView gv = new GridView();
gv.AutoGenerateColumns = true;
gv.DataSource = listOfEntities;
gv.DataBind();
// set alignment for description column
gv.Columns[0].ItemStyle.HorizontalAlign = HorizontalAlign.Left;
On the last line I get index was out of range error, and indeed if I inspect the GridView there's no columns yet. The Entity I am binding has 2 properties and they get rendered OK if I don't try to align them.
Is there a way to do this without having to dynamically assign a delegate to the DataBoundEvent of the gridview?
View 1 Replies
Similar Messages:
Aug 30, 2010
I have a drop down list that is populated in the page load event from a database table. The drop down has a DataTextField set to a project name and the DataValueField set to the project id (interger). Later I change the dropdowlist selected item with this code in the selectedindexchanged event of a gridview
GridViewRow row = GridView1.SelectedRow;
ddlProjectList.SelectedItem.Text = row.Cells[2].Text;
Does Changing the drop down list with this code cause the DataValueField property to change to the correct Project ID number also? If not is there a better way to do this? actually this code seems to be adding an additional item to the list so that the project i set with this code is listed twice so I don't think my code is correct
View 3 Replies
Mar 31, 2010
I am binding a gridview this this my code.
<asp:GridView ID="GvSearch" runat="server"
AutoGenerateColumns="False" BackColor="White" CssClass="GridViewStyle" BorderColor="#336666" BorderStyle="Double"
BorderWidth="3px" CellPadding="4" DataKeyNames="NBDno" GridLines="Horizontal" OnRowUpdating="GvSearch_RowUpdating" Width="700px">
<Columns>
<asp:BoundField DataField="NBDno" HeaderText="NBDno" SortExpression="NBDno" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:BoundField DataField="NBDType" HeaderText="NBD Type" SortExpression="NBDType" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:BoundField DataField="Division" HeaderText="Division" SortExpression="Division" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:BoundField DataField="GroupIn" HeaderText="Group" SortExpression="GroupIn" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:BoundField DataField="ProjectTitle" HeaderText="Project Title" SortExpression="ProjectTitle" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:BoundField DataField="FundAgency" HeaderText="Funding Agency" SortExpression="FundAgency" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:BoundField DataField="DeadLine" HeaderText="Deadline" SortExpression="DeadLine" DataFormatString="{0:dd/MM/yyyy}" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:BoundField DataField="InternalStatus" HeaderText="Status" SortExpression="InternalStatus" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" /> </asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Update" Text="Re-Send" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle CssClass="RowStyle" ForeColor="Black" BackColor="White" HorizontalAlign="Left" Wrap="False" />
<EmptyDataRowStyle CssClass="EmptyRowStyle" />
<PagerStyle CssClass="PagerStyle" />
<SelectedRowStyle CssClass="SelectedRowStyle" />
<HeaderStyle CssClass="HeaderStyle" HorizontalAlign="Left" Wrap="False" />
<EditRowStyle CssClass="EditRowStyle" />
<AlternatingRowStyle CssClass="AltRowStyle" />
</asp:GridView>
Suppose if ant colum is having large amount of words(100 to 200 words). then after binding the gridview spreads and the form become to big with a scrollbar down side. I want a fixed length paragraph in gridview coloum, so that use can easily read the content.
View 5 Replies
Feb 15, 2011
how to set alignment of label in HeaderTemplate in individual column in gridview in asp .net?
View 1 Replies
Aug 31, 2010
i designed a gridiview, within that ItemTemplate i drew an table then tr then some of td's, now the problem is after every row im getting one empty row. below is my code
<ItemTemplate>
<table cellspacing="0" cellpadding="0" style="border-right:1px solid Black;" >
<tr >
<td width="1%" align="center" style="border-right:1px solid Black;">
<span style="">
<asp:ImageButton ImageUrl="~/inc/img/img1.gif" runat="server"
CommandName="Expand" Style="display: none" Width="11px" />
</span>
</td>
<td width="5%" style="border-right:1px solid Black;" > <%--onclick="ShowMenu( <%# Container.DataItemIndex + 1 %>);--%>
<asp:Label runat="server" Text='<%# Eval("data1")%>'></asp:Label> </td>
<td width="5%" >
<asp:Label runat="server" Text='<%# Eval("data2")%>'></asp:Label>
</td>
</tr>
</table>
View 6 Replies
Jan 16, 2014
Scrollable GridView with Fixed Headers inside ASP.Net UpdatePanel using jQuery Plugin. I have one more question in that. How to adjust the width of the columns headers because for some of my gridviews the headers not showing the proper format. in the gridview I gave HorizontalAlign="Left" and in the columns I gave
<asp:BoundField DataField="XXX" HeaderText="XXX" ItemStyle-Width="150px" HeaderStyle-HorizontalAlign="Left" />
It's not showing in the correct fomart. header is coming to the left side and data is coming to the right side...
View 1 Replies
May 10, 2010
i have a FormView, and i already have a Label control that gets the value of theselected propery inside the FormView, so each time the FormView displays data, i have a Label control that displays individual values, according to the value of the FormView, here is the code:
[code]....
What i would like to do is to know how i could add a DataList instead of a Label, and then each time the FormView databinds an item, to show the value of the DataList How would i go about doing that?
View 10 Replies
Nov 30, 2010
I have a gridview with dropdown boxes. As soon as the complete gridview is databound, I want to loop through ALL the rows and set the values of the dropdown boxe in a row based on the value of another column in the same row. The gridview is databound, all data shows up. The condition "If ddl.Items(j).Value = searchstring Then" evaluates as true, but somehow the selected item in the dropdownbox is NOT changed and remains "<ignore>"
[Code]....
View 5 Replies
Dec 7, 2010
I want to render something like this (with ASP.Net Controls in the codebehind):
<ul>
<li class="first"><h1>This is a caption</h1></li>
<li><a href="#" title="" target="_self">Foo</a></li>
<li><a href="#" title="" target="_self">Foo1</a></li>
<li><a href="#" title="" target="_self">Foo2</a></li>
<li><a href="#" title="" target="_self">Foo3</a></li>
<li><a href="#" title="" target="_self">Foo4</a></li>
</ul>
<ul>
<li class="first"><h1>This is a another caption</h1></li>
<li><a href="#" title="" target="_self">Foo5</a></li>
<li><a href="#" title="" target="_self">Foo6</a></li>
<li><a href="#" title="" target="_self">Foo7</a></li>
<li><a href="#" title="" target="_self">Foo8</a></li>
<li><a href="#" title="" target="_self">Foo9</a></li>
<li><a href="#" title="" target="_self">Foo10</a></li>
<li><a href="#" title="" target="_self">Foo11</a></li>
</ul>
The amount of li elements that will be rendered into each ul is determined at runtime. Each link in a li belongs to into a specific ul (the one containing a specific caption. Imagine this as a kind of a treeview with nodes and subnodes) During the bind Event I need access to an ASP:HyperLink that will be rendered into the a-element. Which databound ASP.Net control should I pick for this? Looks like a repeater in a repeater, which should make the databinding process ugly. I'm thinking about creating this HTML-Output with StringWriters myself.
View 1 Replies
Sep 2, 2010
1) For some reason the MainDivision column in this is displaying bold and centered (the rest are left and not bold). Anybody see something that creeped into this markup that might be causing this?
HTML Code:
[code]....
2) How can I add a non-databound checkbox to a gridview? It only seems to appear if I bind it to something, but I want it so the user can check which rows he wants to perform an action against, so it has no value other than UI interaction.
View 3 Replies
Dec 14, 2010
I have a table in the itemtemplate of a gridview.
My requirement is something like what's shown in the below link
[URL]
i.e. Say 3, 4 and 5 are user id's. The middle column can contain some information about that user. Say for User 3 we have Info 1, Info 2 and Info 3 in those three rows. Similarly, for user 4 and 5, we would have some values in the middle column.
The number of rows in the middle column can vary. It depends on the number of rows returned by the DB call for that user.
So, how can I achieve this using grid view?
Will it be possible for me to add rows in the databound event dynamically by looking at the previous or next row in the datasource? If so, how should I go about it?
View 2 Replies
Aug 10, 2010
I was just wondering what is the best way to fetch gridview data using row databound event of gridview. I am previously used to Eval but read its not recommended as it uses reflection.
View 1 Replies
Nov 28, 2010
I've been working on a colleagues site, and have been unable to fix a coupld of issues with it. One of which is a refresh of a Gridview panel.
The page allows a user to navigate a tree structure and then display the permissions on a user selected folder. Permissions are then added/removed and Saved.
What's not happening is the saved changes aren't being refreshed in the Gridview, also after doing this process once selecting another folder doesn't refresh the Gridview either.
Below is the sa.aspx file
[Code]....
Below is the associated sa.aspx.cs
[Code]....
View 3 Replies
Feb 9, 2010
I have given an access to stored procedure, which i'm not able to edit. This Stored Procedure returns a Table with 2 Column, what I did is set a GridView's DataSource using SQLDataSource in this stored procedure. but I want this GridView to Sort an specific column to descending whenever this GridView Loads.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2" ForeColor="Black"
Width="58%" Height="125px" AllowPaging="True" AllowSorting="True"
PageSize="5" >
<Columns>
<asp:BoundField DataField="DateOccur" HeaderText="Login Date"
SortExpression="DateOccur" />
<asp:BoundField DataField="TotalMinutesPlayed" HeaderText="Total Minutes"
SortExpression="TotalMinutesPlayed" />
</Columns>
<AlternatingRowStyle BackColor="#EFEFEF" />
</asp:GridView>
View 2 Replies
Sep 21, 2010
I have a gridview I bound a DataTable with that Gridview Its dynamic so no hardcode Text in desin.
I tried to change it after Databound and in PreRender of gridview but no Success.
Actually there are Underscores('_') in text and I want to Replace it with space.
Below is code
<asp:GridView ID="grdSearchResult" runat="server" AutoGenerateColumns="True" Width="99%" OnPreRender="grdSearchResult_PreRender"
OnRowCreated="grdSearchResult_OnRowCreated" OnPageIndexChanging="grdSearchResult_PageIndexChanging">
<HeaderStyle ForeColor="White" BackColor="#215B8D" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<RowStyle CssClass="gridtext" HorizontalAlign="Center" />
</asp:GridView>
protected void grdSearchResult_PreRender(object sender, EventArgs e)
{
for (int i = 0; i < grdSearchResult.Columns.Count; i++)
{
grdSearchResult.Columns[i].HeaderText = grdSearchResult.Columns[i].HeaderText.Replace("_", "");
}
}
View 2 Replies
Feb 25, 2011
I am trying to add an image overlay of a cell within a data bound gridview cell in ASP.Net (C#). The effect is designed to have a string within the image that is going to sit on top of the image that is pulled from the server.
IE: Database contains path to images. Data grid is pulling these images in based on the ID of the items in question. I need to pull the price from the database and lay it onto an image that is placed over the data bound image cell.
SQL Statement gets results.
Results contains path to image for items.
Items are sometimes on sale, so a special overlay is needed.
Overlay will have a varying price overlaying it.
I tried to break it down into easy portions. I am not sure if I am over thinking things or not but I can't find a feasible way to do this. The data is converted to a table due to the data grid control in ASP.Net, and there isn't any way to determine the IDs after the table is created.
View 1 Replies
Sep 23, 2010
i have to a grid view and the datasource for it is a table coming from the database the table containing sequence numbers for example if the sequence number is 1 then i want to add a row just above this saying it is the start , the entire row should give some information .
i tried to find related thing but no luck, waiting for some replies to move further
View 5 Replies
Nov 12, 2010
I need to be able to get the value in the "first" row of a Gridview as its getting or right after it is displayed.
I thought this would work but its coming up null.
I'm using the DataBound event to get the value of the control of a selected row...assuming the selected row is the first row which is probably the error of my ways. Any ideas how to get at this value easily?
[Code]....
View 1 Replies
Apr 13, 2010
I am trying to develop a very simple templated custom server control that resembles GridView. Basically, I want the control to be added in the .aspx page like this:
[Code]....
I know that what I want to achieve is pointless and that I can use DataGrid to achieve it, but I am giving this very simple example because if I know how to do this I would be able to develop the control that I need.
View 1 Replies
Nov 7, 2010
How can i do the following:
I already have an ArrayList populated from an Oracle table using SQL Select statement.
[Code]....
View 6 Replies
Dec 29, 2012
this is my hyperlink code that is in gridview
<ItemTemplate>
<asp:HyperLink ID="lnkRemove2" runat="server" CssClass="LBP3E" Text = "more..." NavigateUrl='<%# "state/view.aspx?BehCode=" + Request.QueryString["BehCode"] + "&Id=" + Eval("Id") %>'></asp:HyperLink>
</ItemTemplate>
I want do some thing like that for my button control that is not in gridview it is out of grid view...HOw I can do it?
View 1 Replies
Mar 1, 2014
This is my for loop code, it is working fine , just the problem is, if there are 10 rows , it runs for 9 rows and not for 10th time? What correction is needed?
protected void gvouter_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int count_rows_for_saving_answers = gvouter.Rows.Count;
for (int ii = 0; ii <= count_rows_for_saving_answers - 1; ii++)
{
Label lblsubid = (Label)gvouter.Rows[ii].FindControl("lblsubid");
[Code].....
View 1 Replies
Jun 17, 2010
I have two gridviews, where the first is databound to a sql table (but does not display the primary key info), and want to filter the data displayed on the second gridview by using the primary key info from the first gridview table, indicated by the selected row in the first gridview - how I could achieve this? its kind of like using the gridviews as a menu and sub menu display!
View 1 Replies
Jan 10, 2010
I want to created a messaging system and to display the messages. I want to use a gridview. My problem is how can I display the new messages in BOLD rows and the readed messages in normal text.
View 7 Replies
Apr 6, 2010
I have a data bound column in grid view. When a particular value in a cell is getting processed I want to display an image in the cell.
View 2 Replies