哈西表作为数据源: Hashtable tabValues = new Hashtable(5); tabValues.Add("Microsoft", 49.56); tabValues.Add("Sun", 28.33); tabValues.Add("IBM", 55); tabValues.Add("Compaq", 20.74); tabValues.Add("Oracle", 41.1); // set the DataSource property of the controls // first <select> displays the Keys in the HashTable MySelectList1.DataSource = tabValues; MySelectList1.DataTextField = "Key"; 数据源为datareader: OleDbConnection objConnect = new OleDbConnection(strConnect); // open the connection to the database objConnect.Open(); // create a new Command using the connection object and select statement OleDbCommand objCommand = new OleDbCommand(strSelect, objConnect); // execute the SQL statement against the command to get the DataReader objDataReader = objCommand.ExecuteReader(); MyDataGrid.DataSource = objDataReader; MyDataGrid.DataBind();
这个谁说的?只要是数据就行
private void Form1_Load(object sender, System.EventArgs e)
{
codeDataTable = new DataTable("CodeTable");
codeDataTable.Columns.Add("Modifier");
codeDataTable.Columns.Add("PropertyName");
codeDataTable.Columns.Add("Type");
codeDataTable.Columns.Add("Comment");
dataGrid1.DataSource = codeDataTable;
comboBox1.Text = comboBox1.Items[0].ToString();
} private void dataGrid1_MouseDown(object sender, MouseEventArgs e)
{
DataGrid myGrid = (DataGrid) sender;
DataGrid.HitTestInfo hitInfo = myGrid.HitTest(e.X, e.Y);
int col = hitInfo.Column;
int row = hitInfo.Row;
if( hitInfo.Type == DataGrid.HitTestType.Cell )
{
if( row > codeDataTable.Rows.Count - 1 || ( row == 0 && codeDataTable.Rows.Count == 0) )
{
string[] defaultValue = {this.defaultModifier , this.defaultPropertyName , this.defalutType };
codeDataTable.Rows.Add(defaultValue);
myGrid.Update();
}
} }
Hashtable tabValues = new Hashtable(5);
tabValues.Add("Microsoft", 49.56);
tabValues.Add("Sun", 28.33);
tabValues.Add("IBM", 55);
tabValues.Add("Compaq", 20.74);
tabValues.Add("Oracle", 41.1); // set the DataSource property of the controls // first <select> displays the Keys in the HashTable
MySelectList1.DataSource = tabValues;
MySelectList1.DataTextField = "Key";
数据源为datareader:
OleDbConnection objConnect = new OleDbConnection(strConnect); // open the connection to the database
objConnect.Open(); // create a new Command using the connection object and select statement
OleDbCommand objCommand = new OleDbCommand(strSelect, objConnect); // execute the SQL statement against the command to get the DataReader
objDataReader = objCommand.ExecuteReader();
MyDataGrid.DataSource = objDataReader;
MyDataGrid.DataBind();
给你个例子了
<ASP:DATAGRID id="DataGrid1" runat="server" BorderColor="#D7DFE8" BorderWidth="1px" CellPadding="1"
Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#E7F0F9" HeaderStyle-font-weight="fold"
AutoGenerateColumns="False" width="100%" BackColor="#ffffff" Font-Names="Verdana" AllowPaging="true"
PageSize="15" PagerStyle-Mode="NumericPages">
<HeaderStyle Wrap="False" CssClass="tttable" BackColor="#E7F0F9"></HeaderStyle>
<SelectedItemStyle Wrap="False"></SelectedItemStyle>
<EditItemStyle Wrap="False"></EditItemStyle>
<AlternatingItemStyle Wrap="False" BackColor="#F6F6F6"></AlternatingItemStyle>
<ItemStyle Wrap="False"></ItemStyle>
<Columns>
<asp:BoundColumn DataField="帮定的数据库字段" HeaderText="你想显示的字段名">
<ItemStyle Wrap="False" Width="8%"></ItemStyle>
</asp:BoundColumn>
</Columns>
</ASP:DATAGRID>
你可以自己试着看看以上关于DataGride 各属性具体的效果
早日进步..
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
还有msdn