add an expression columnYourDataTable.Columns.Add("MyKey", typeof(string), "Column1 + '#' + Column2");DataGrid1.DataSource = YourDataTable.DefaultView; DataGrid1.DataKeyField = "MyKey"; DataGrid1.DataBind();and when you get the key value, use split
来自saucer add another column to your data tableYourDataTable("MyKey", typeof(string), "key1 + '#' + key2 + '#' + key3");you might need to convert your key to a string type, for example YourDataTable("MyKey", typeof(string), "Convert(key1,'System.String') + '#' + key2 + '#' + key3");YourDataGrid.DataKeyField = "MyKey"; ...string [] slist = YourDataGrid.DataKeys[YourItemIndex].ToString().Split('#');
但是你可以把你的主键绑到在Label.Text上面,并且把样式设置为Display:NONE就可以了
效果一样
DataGrid1.DataKeyField = "MyKey";
DataGrid1.DataBind();and when you get the key value, use split
add another column to your data tableYourDataTable("MyKey", typeof(string), "key1 + '#' + key2 + '#' + key3");you might need to convert your key to a string type, for example
YourDataTable("MyKey", typeof(string), "Convert(key1,'System.String') + '#' + key2 + '#' + key3");YourDataGrid.DataKeyField = "MyKey";
...string [] slist = YourDataGrid.DataKeys[YourItemIndex].ToString().Split('#');