(Forum Q & A Drop) Joint primary key How to use Datakeys positioning records in DataGrid?

xiaoxiao2021-03-05  30

For example, the three fields of the table Key1 Int, Key2 Int, Item Varchar (50) combined with primary key front desk:

<

ASP: DATAGRID

id

= "DataGrid1"

Runat

= "Server"

AutogenerateColumns

= "False"

Datakeyfield

= "DoubleKey"

>

<

Columns

>

<

ASP: BoundColumn

Datafield

= "item"

Headertext

= "item"

>

ASP: BoundColumn

>

<

ASP: ButtonColumn

CommandName

= "DEL"

TEXT

= "Delete"

>

ASP: ButtonColumn

>

Columns

>

ASP: DATAGRID

>

Backstage code:

Using

System;

Using

System.collections;

Using

System.componentmodel;

Using

System.data;

Using

System.data.sqlclient;

Using

System.drawing;

Using

System.Web;

Using

System.Web.SessionState;

Using

System.Web.ui;

Using

System.Web.ui.WebControls;

Using

System.Web.ui.htmlControls;

Namespace

9CBS2

{Public class WebForm20: System.Web.UI.Page {protected System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load (object sender, System.EventArgs e) {if (IsPostBack!) {SetBind ();}} private void SetBind () {SqlConnection conn = new SqlConnection (System.Configuration.ConfigurationSettings.AppSettings [ "conn"]); SqlDataAdapter da = new SqlDataAdapter ( "select * from doublekey", conn); DataSet ds = new DataSet (); Da.Fill (DS); DataTable DT = DS.TABLES [0]; Datacolumn DC = New Datacolumn ("DoubleKey", TypeOf (String), "Key1 '#' key2"); dt.columns.add (DC) This.dataGrid1.datasource = DT; this.dataGrid1.database ();} Web Form Designer Generated Code #Region Web Form Designer Generated Code Override Protected Void OnInit (Eventargs E) {//// Codegen : This call is ASP.NET Web Form Designer is required. // InitializeComponent (); base.oninit (e);} / ** ////

/// Designer supports the required method - do not use the code editor to modify the // / this method.

转载请注明原文地址:https://www.9cbs.com/read-34425.html

New Post(0)