.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Gridview Header & table data alignment problem

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :ASP.Net


Newbie to ASP.net. Programming in C#.

I'm querying a SQL database and displaying the results in a gridview.

The results can be many records so I need to provide the facility to scroll. To display the headers when scroling I have implemented ( in my asp code) the headers in another table and the data is in another table. I see now I cannot align the column headers with the table data.

Appreciate any help to fix this issue.

If this method is not a good one to display headers with data please suggest another method.( Some example code guidance would really help)

Here is my ASP code.

<div id="divProjectTableHeaderFullDetail" runat="server" style="background-color: #993300;
            height: 40px; width: 770px; margin: 0;  padding: 0 ; " >
            <table style="font-family: Arial; font-size: 10pt; color: white;" cellspacing="0"

View Complete Post

More Related Resource Links

gridview table alignment problem

hi all, 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, what is the problem and how to resolve it. 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;">          &n

problem...i want a list item to populate all data in gridview!!!


i have a dropdownbox and a gridview

what I want is to have a list item which populates all data in a gridview.

I have tried using list item selected value=0 but to no avail.

what is the easiest way to achieve this?

Problem with Conversion of numeric data from sql table to csv

I have a numeric value which is of data type Numeric(38,12) in sql server 2000. Now loading to csv what happens is 2000--data looks like 115,834,000.00 when loaded to csv ---115834000--this is how it looks. but I want it to look like as it is in the database. It would be of great help to me, if anybody can tell me the work around. Thanks, PreenSheen

GridView column/row data binding problem

Hi All, I have a table with the following structure: Attribute------------- AttributeIdWeekNoDayNoAttribute1Attribute2Attribute3Attribute4Attribute5 ........ likewise. I want to display these data in a gridview in the following manner                                  Sunday    Monday Tuesday ............ (till Saturday) - should be gridview columns, I can retrieve this using dayno Attribute 1 Attribute 2 Attribute 3 Attribute 4 .......... like wise attributes should be taken in to rows.Is this possible in a gridview, if so how can I do that?

Problem when Inserting xml data into a table using OpenXml

Hi, i stuck with a problemam trying to insert data from xml file to sql server.i made query like thisSET NOCOUNT ON DECLARE @hDoc INT EXEC sp_xml_preparedocument @hDoc OUTPUT, '<NewDataSet>  <xs:schema id=''NewDataSet'' xmlns='''' xmlns:xs=''http://www.w3.org/2001/XMLSchema'' xmlns:msdata=''urn:schemas-microsoft-com:xml-msdata''>  <xs:element name=''Job''>     <xs:complexType>      <xs:sequence>        <xs:element name=''BillToNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''Colors'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CompanyNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CsrCode'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CsrName'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''CustomerPoNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''DivisionOriginal'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''EstimateNo'' type=''xs:string'' minOccurs=''0'' /> <xs:element name=''FinalDeliveryDate'' type=''xs:string'' minOccurs=''0'' /> <xs:element name

pull some data from a table twice for same gridview


 Hello all - I have been searching google for a solution to this problem but I'm having difficulty describing it in keywords.

environment:  VWD 2010 Express, VB, SQL Express, .NET 4.0

I have a gridview that currently pulls data from a table called CrossRef which has the ID numbers of tasks that need to go in a certain sequence.  So the gridview looks like:

Task 1       Sequence          Task 2           XRefID

10               BEFORE             22                 4

2                AFTER                6                  5

17              BEFORE              2        

Problem with getting extra data in column of gridview


I have created a gridview based on an SQL Datasource.  The grid view contains several columns(fields) one of which is called "Amount".  In the footer of the gridview their is a field that contains the sum of all of the values contained in the "Amount" field.

By problem is that in instead of getting the value of the Amount displayed in the "Amount" field of each row, I am getting a '0' (Example: 0 25.78 when I should just be getting 25.78.  There is a space between the '0' and the '25.78'.

Code is as follows:


<asp:TemplateField HeaderText="Amount" SortExpression="Amount">

Insert XML data into table problem


For the life of me I cannot figure out what's wrong with my SP. I'm receiving an XML document with a bunch of invoices like


And I need to write each invoice as a record in SQL Server 2005

I'm getting the following error

Msg 170, Level 15, State 1, Procedure pcdAddInvoices, Line 39
Line 39: Incorrect syntax near '.'.


 -- Add the parameters for the stored procedure here

 @msg xml
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.

    -- Insert statements for procedure here
 INSERT INTO [Promacoin].[dbo].[Tblinvoices_DAX] (ObjectID,ActivityID,ResourceID,ContractID,Document
 SELECT M.Invoice.value('/ObjectID','NVARCHAR(16)') AS ObjectID,

export the gridview data to excel problem



i am using master page and child pages in the child page

i want to export the gridview data to excel sheet for this i use the following code


        Response.AddHeader("content-disposition", "attachment; filename=shedules.xls");

        Response.ContentType = "application/excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);




but in the gridShedules.RenderControl(htw) i got the following error but the form tag with  runat= server is already in the master page how to solve this issue

error:Control 'ctl00_ContentPlaceHolder1_grdshedules' of type 'GridView' must be placed inside a form tag with runat=server.

problem with data list when data is retrieved from table???



I have a datalist binded to an object data source which has a method



In the  data list Item template, I have put  a div with a heading that will not show if there is no language by that personId  in the database table.

If there  is data them problem is the datalist repeates the heading for each language instead of showing  just the heading above and the row of languages below. I have included all my code below if somebody could advise what is wrong. thank you.


Method in DAL

SELECT        PersonId, LanguageId,
 (SELECT LanguageName FROM Language WHERE (LanguageId = PersonLanguage.LanguageId)) AS LanguageName
FROM            PersonLanguage
WHERE        (PersonId = @PersonId)



 <asp:DataList ID="DataList3" runat="server" DataKeyField="ModelId"
        DataSourceID="ObjectDataSource4" RepeatDirection="Horizontal" >
        <div id="Div03"&n

Problem filling labels with table data outside datalist using single call to db


On a single page, I'd like to fill 2 hyperlink controls as well as a datalist control with table data using one call to the database. The page looks like this:

<div id="PageContent">    
      Please select the district you wish to view below.</p>
      <asp:DropDownList ID="ddlDistrict" runat="server" CssClass="textbox" 
        DataTextField="DistrictName" DataValueField="DistrictId" AutoPostBack="True" 
    <p><asp:label ID="lblDistrictAbbrev" runat="server" Text="District Abbreviation: " />
      <asp:hyperlink ID="hyperlinkDistrictName" runat="server" 
        Text='' NavigateUrl="~/Contact/NationalCouncil.aspx" 
        Font-Bold="True" />
    <p><asp:label ID="lblDistrictCouncillor" runat="server" Text="District Councillor: " />
      <asp:hyperlink ID="hyperlinkCouncillor" runat="server" 
        Text='' NavigateUrl="~/Contact/NationalCouncil.a

How to INSERT GridView data into another table (besides the one it is bound to)??


Hi All,

I have a tricky situation that I just cannot seem to figure out.  I'm using ASP.NET 4.0.  I have two databases (let's call them Northwind and MyDatabase for simplicity).  I cannot modify the data in Northwind, but once I save a copy to MyDatabase, I can change it.

I have a GridView that shows all the tests associated with a patient.  I first populate the GridView, retrieving all the tests in Northwind.Test that are associated to a PatientID.  On a button click event, I need to:

  1. Create a new Patient record in MyDatabase.Patient (I've got this part done already).
  2. Use that newly created PatientID and INSERT all of the rows from the GridView into MyDatabase.Test.  I have the PatientID available, I just don't know how to retrieve the data from the GridView.
  3. (Ideally) I would like to then be able to load that patient record in the future from MyDatabase and be able to UPDATE the tests in the GridView to MyDatabase.Test.

I can load the tests into the GridView no problem.  But I have no idea how I would save that data to a different datasource.  Any ideas?  Should I even be using a GridView, or something else?

-Thanks in advance-

Problem adding multiple header rows to a gridview


Hello all!

I'm having difficulty adding a repeating header row, every x rows, to a gridview.  I'm able to add the header only once with the below code.  For some reason it will only add it during the last iteration through the for/next statement.  I tried manually adding three separate .addat statements to different rows and it only executed the last .addat statement.  I couldn't find any information on why it's only working the one time and I hope someone has a fix or better solution.

Thanks in advance!

Code snippet (Note the IsWhole() function verifies that the rownumber divided into a whole number):

Protected Sub Gridview1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles Gridview.DataBound

        Dim grid As GridView = TryCast(sender, GridView)

        If grid IsNot Nothing Then

            Dim row As New GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Normal)
            Dim header As GridViewRow = POSTURE_RESULT.HeaderRow
            For i As Integer = 0 To POSTURE_RESULT.Columns.C

Why when I click on title header to sort a GridView, some data disappear?


 Hi there

When I click on my GridView header "End Time" all the rows which contain the string "N/A" disappear.
Here is my code:

protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
FillDataGridView_JobHistory(ViewState["DateBegin"].ToString(), ViewState["DateEnd"].ToString());

Note: GetSortDirection returns "endTime ASC" or "endTime DESC" and save in ViewState:

ViewState["SortDirection_JobHistory"] = sortDirection;
ViewState["SortExpression_JobHistory"] = column;

Then I fill the DataAdapter and use the ViewState info to sort it:

protected void FillDataGridView_JobHistory(string dateBegin, string dateEnd)
string query = "dbo.GetJobHistory";
DataTable dt = new DataTable();
SqlConnection myConnection = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);

SqlCommand cmd = new SqlCommand(query, myConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@dateBegin", SqlDbType.DateTime));
cmd.Parameters.Add(new SqlParameter("@dateEnd", SqlDbTyp

gridview alignment problem


I have a table in which  gridview1 is created when the user clicks a button outside this table.

when the user then clicks on a rowcommand button from Gridview1 a second gridview, chldgrdvw, is created in the next cell on the same row of the table.

My issue is that I would like the second gridview (chldgrdvw) to align with the the row clicked from gridview1.  Currently I can only get chldgv to align based on its table cell properties ie (top of cell, left of cell, bottom of cell etc..)

using data in a gridview to update a table



I have a gridview that gathers data from two tables, an orders table and a products table. I have an OrderQuantity from the Orders table and a StockQuantity from the Products table and a button to process the order.

I am trying to move through the GridView one line at the time, substract the OrderQuantity from the StockQuantity and update the Product table.

How do I move through the GridView?



Editing the Data in a GridView

In addition to deleting a GridView's underlying data, another common need is to allow end users to edit the data displayed in a GridView. With ASP.NET 1.x's DataGrid control, editing the data is certainly possible, but requires creating three event handlers and writing a dozen or so lines of code. With the GridView and ASP.NET 2.0, it is possible to create an editable GridView without writing a single line of code! All of the necessary functionality is encapsulated within the GridView.

The GridView allows editing on a row-by-row basis. An editable GridView contains an additional column with an Edit button in each row. When the end user clicks on an Edit button that row becomes editable, causing the Edit button to change to Update and Cancel buttons and the other columns to become TextBoxes. The end user can then update one or more column values and click Update to save their changes.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend