How does a DataGrid generate a category question header?

Source: Internet
Author: User
When I write powerdatagrid, I want to provide a query (for more information about powerdatagrid, refer to the discussion post in the csdn Forum. The source code can be downloaded at www.foxhis.com/powermjtest/?powerdatagrid.rar). The idea of this query is as follows: my control can display the content of this statement by specifying an SQL statement (other functions are not described, which is not the focus ), then I can encapsulate a set of UIS in this control to implement the query function. The problem arises. This query should usually be on the DataGrid, that is, the query result, how can I retain the original question header and add another question header )?
The problem arises. How can this problem be solved? If you want to repeat the headers and sort the headers, you must add new headers without moving the original headers. When you do not intend to publish a page, you can use several paging display methods. In the paging panel, you can select the position where the page is to be selected, and you can select the upper/lower type, when this type is selected, the DataGrid has another row on the original header. Today we will use this row to complete our task, today, we do not generate a query UI but a Classification Topic. We use employees in the test database northwind to display data. The first thing we need to do is to bind data binding. Code As follows:
Sqlconnection con = new sqlconnection ("Server = localhost; database = northwind; uid = sa; Pwd = ;");
Sqldataadapter da = new sqldataadapter ("select lastname +'' + firstname as name, birthdate, country, title, hiredate from employees ", con );
Datatable dt = new datatable ();
Da. Fill (DT );
This. Maid = DT;
This. datagrid1.databind ();
}
Next, we add the appropriate code in itemcreated to complete our task. In the event processing function of powerdatagrid, we have added a UI for creating a custom page! If you add two (up and down) pager locations to the powerdatagrid, we can use a global variable to determine.
Define a global variable private int m_createpagetimes = 0;
Then we add the following code for the event handler:
Private int m_createpagetimes = 0;
Private void maid (Object sender, system. Web. UI. webcontrols. datagriditemeventargs e ){
Listitemtype elemtype = E. Item. itemtype;
If (elemtype = listitemtype. pager ){
If (m_createpagetimes = 0 ){
Tablecell cellperson = (tablecell) E. Item. controls [0];
Cellperson. Controls. Clear ();
Cellperson. backcolor = color. Navy;
Cellperson. forecolor = color. Yellow;
Cellperson. columnspan = 3;
Cellperson. horizontalalign = horizontalalign. Center;
Cellperson. Controls. Add (New literalcontrol ("personal information "));

Tablecell celljob = new tablecell ();
Celljob. backcolor = color. Navy;
Celljob. forecolor = color. Yellow;
Celljob. columnspan = 2;
Celljob. horizontalalign = horizontalalign. Center;
Celljob. Controls. Add (New literalcontrol ("Job Info "));
E. Item. Controls. Add (celljob );
M_createpagetimes ++;
} Else if (m_createpagetimes = 1 ){
// Create M pager UI
}
}
The code for the HTML part of the DataGrid is as follows:
<Asp: DataGrid id = "datagrid1" runat = "server" allowpaging = "true" autogeneratecolumns = "false" width = "100%"
Pagesize = "2">
<Columns>
<Asp: boundcolumn datafield = "name" headertext = "name"> </ASP: boundcolumn>
<Asp: boundcolumn datafield = "birthdate" headertext = "Birthday"> </ASP: boundcolumn>
<Asp: boundcolumn datafield = "country" headertext = "country"> </ASP: boundcolumn>
<Asp: boundcolumn datafield = "title" headertext = "title"> </ASP: boundcolumn>
<Asp: boundcolumn datafield = "hiredate" headertext = "employment date"> </ASP: boundcolumn>
</Columns>
<Pagerstyle position = "topandbottom" mode = "numericpages"> </pagerstyle>
</ASP: DataGrid>
The running effect is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.