Results 1 to 2 of 2

Thread: DataGrid in ASP.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Location
    India
    Posts
    3

    Red face DataGrid in ASP.Net

    I wrote a query "select * from tbl_School".
    tbl_School has 7 columns say rollno, name, standard, sub1,sub2, sub3, Score.
    Now I want to fill a DatagridOne using the above written query inwhich I will display first there columns(rollno, name, standard) and I want to fill an another DatagridTwo having the rest of the columns(Sub1, Sub2, Sub3 & Score) using the same query.

    The problem is I do not want to write separate query for both the datagrids but want to use a common above written query. how is it possible?
    ~Vishal

    Keep Smiling...

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    use the query to create a datatable and then build two sepearte datagrids. You can add code to the html page to specify the columns to be used.

    add this tag to datagrid one.
    VB Code:
    1. <Columns>
    2.                     <asp:BoundColumn DataField="chnl_id" HeaderText="Channel ID"></asp:BoundColumn>
    3.                     <asp:BoundColumn DataField="district" HeaderText="District"></asp:BoundColumn>
    4.                     <asp:BoundColumn DataField="range01" SortExpression="range01" HeaderText="0 - 30 days" DataFormatString="{0:c}"></asp:BoundColumn>
    5.                     <asp:BoundColumn DataField="range02" SortExpression="range02" HeaderText="31 - 60 days" DataFormatString="{0:c}"></asp:BoundColumn>
    6.                
    7. </Columns>
    and then for datagrid two:
    VB Code:
    1. <asp:BoundColumn DataField="range03" SortExpression="range03" HeaderText="61 - 90 days" DataFormatString="{0:c}"></asp:BoundColumn>
    2.                     <asp:BoundColumn DataField="range04" SortExpression="range04" HeaderText="91 - 180 days" DataFormatString="{0:c}"></asp:BoundColumn>
    3.                     <asp:BoundColumn DataField="range05" SortExpression="range05" HeaderText="180 - 365 days" DataFormatString="{0:c}"></asp:BoundColumn>
    4.                     <asp:BoundColumn DataField="value90" SortExpression="value90" HeaderText="90 + days" DataFormatString="{0:c}"></asp:BoundColumn>
    5.                     <asp:BoundColumn DataField="value" SortExpression="value" HeaderText="Total" DataFormatString="{0:c}"></asp:BoundColumn>

    obviously chnage the boundcolumn datafield to your column name

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width