successditemstyle> <
ItemStyle ForeColor = "# 330099" BackColor = "White"> ItemStyle> HeaderStyle> FooterStyle> PagerStyle> < ItemTemplate> <% # Container.DataSetIndex 1%> ItemTemplate> asp: TemplateColumn> asp: BoundColumn> asp: BoundColumn> Columns> asp: datagrid>
asp: button> form> body> html> =========== =================================================================================================================================================================================================================================
============================================= (1) temporary table method private void GetData () {SqlConnection cnn = new SqlConnection (System.Configuration.ConfigurationSettings.AppSettings [ "SqlServer"]); SqlCommand cmd = new SqlCommand ( "select identity (int, 1,1) as customID, * into #t From sysusers; select * from #t ", cn); sqldataadapter adapter = new SqlDataAdapter (CMD); DataSet DS = New Dataset (); try {adapter.fill (DS); dataGrid1.datasource = ds.tables [0]. DEFAULTVIEW; DATAGRID1.DATABIND ();
} Catch (Exception ex) {Response.Write (ex.ToString ());}} (two) columns configured value from private void GetDataByAddingColumn () {SqlConnection cnn = new SqlConnection (System.Configuration.ConfigurationSettings.AppSettings [ "SqlServer" ]); SqlCommand cmd = new SqlCommand ( "select * from sysusers", cnn); SqlDataAdapter adapter = new SqlDataAdapter (cmd); DataSet ds = new DataSet (); DataTable dt = new DataTable ( "tmpTable"); DataColumn dc = New Datacolumn ("CustomID", TypeOf (System.Int32)); dc.autoincrement = true; dc.autoincrementSeed = 1; dc.AutoincrementsTep = 1; DT.COLUMNS.ADD (DC); try {adapter.fill DataGrid1.datasource = DT.DEFAULTVIEW; DATAGRID1.DATABIND ();} catch (exception ex) {response.write (ex., you need to pay attention to the order of operation, first constructive table, then Turn Adapter.Fill (DT), otherwise you can not yell, don't jeak me, 自己 自己! ^ _ ^ (3) Dynamic build self-value value display column when binding
<% # Container.DataSetIndex 1%> itemtemplate> asp: templateColumn> ASP: TEMPLUMN>
Maybe you see that you will choose the third method without hesitation, moving your own brain, the first two methods are also useful D! =================== =========================
Some of the code that calls the function in the CS is like this:
In this routine, you can test the first and third solutions.
Private void page_load (object sender, system.eventargs e) {if (! ispostback) {getData ();}}