how to bind a datagrid?
i tried to bind a datagrid but there is a problem in binding of my datagrid..
C# code
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("Source");
dt.Columns.Add("ID", Type.GetType("System.String"));
dt.Columns.Add("Desc", Type.GetType("System.String"));
Insurance oInsurance = new Insurance();
List<Value> lstValue = oInsurance.Category.ValueList;
foreach (Value item in lstValue)
{
DataRow dr = dt.NewRow();
dr[0] = item.Key.ToSt开发者_如何学Cring();
dr[1] = item.Value.ToString();
dt.Rows.Add(dr);
}
grdCategory.DataSource = ds;
grdCategory.DataMember = "Source";
grdCategory.DataTextField = "Desc";
grdCategory.DataValueField = "ID";
grdCategory.DataBind();
Thanks
well... try to post the error that you are getting from this...
but... if you don't need the DataSet you could just do like this...
Insurance oInsurance = new Insurance();
List<Value> lstValue = oInsurance.Category.ValueList;
grdCategory.DataSource = lstValue;
grdCategory.AutoGenerateColumns = true; //not sure that's the property
grdCategory.DataBind();
精彩评论