By this
code we can set Grid header name from our database table daynamicaly.
private void bindDataExpensesNew()
{
DataTable
oldTable = new DataTable();
DataTable
dtdataExpns = new DataTable();
oldTable = ObjBll.GetItemtest();
for
(int i = 2; i <= oldTable.Rows.Count+2; i++)
{
dataGridView1.Columns[0].HeaderText = "To
Date";
dataGridView1.Columns[1].HeaderText = "From
Date";
for
(int j = 0; j <= oldTable.Rows.Count; j++)
{
dataGridView1.Columns[j].HeaderText =oldTable.Rows[j]["name"].ToString();
}
}
}
Page
load:
private void Form2_Load(object
sender, EventArgs e)
{
bindDataExpensesNew();
}
BLL file code:
public DataTable GetItemtest()
{
string
str = "select name from table;
dt = ObjDAL.GetResultFromSqlQur(str);
return
dt;
}
No comments :
Post a Comment