what I have done with a grid view is .. According to ma database i have added columns to the datatable and after that i binded it to a gridview.,
here is the code,
/// Get Activities here to bind to GridView To Get the Activities at first Column.
Dt = BlObj.BlDynamic_Table("[USP_DynamicGridView]", 2);
DtOperation = BlObj.BlDynamic_Table("[USP_DynamicGridView]", 1);
for (int i = 0; i < DtOperation.Rows.Count; i++)
{
Dt.Columns.Add(DtOperation.Rows[i][0].ToString());
}
dgrDynamic.DataSource = Dt;
dgrDynamic.DataBind();
but for me needed is to get the column index.. here is the code
private int GetColumnIndexByName(int p)
{
return ((int)GetColumnName(BlObj.BlDynamic_Table("[USP_DynamicGridView]",
4, p).ToString()));
}
private int GetColumnName(string name)
{
foreach (DataColumn col in dgrDynamic.Columns)
{
int Index = 0;
if(col.Equals(name.ToLower().Trim()))
// if (col.Name.ToLower().Trim() == name.ToLower().Trim())
{
return Index;
}
Index += 1;
}
return -1;
}
What the problem is the foreach loop is not working..
I'm a fresher to .NET and I also don't know whether I have followed the right way.. can anybody please help me?
Thanks in advance.