Reputation: 126
I'm new to gridviews and I'm a bit confused.
My gridview has autogeneratecolumn on false and I use
GridView1.DataSource = reader;
GridView1.DataBind();
to fill the gridview. From what I understand, I have to use a RowCreated function to pull a value?
I have to parse all the values in one column.
Upvotes: 0
Views: 82
Reputation: 3662
You can use RowDataBound Event of the Gridview.
OnRowDataBound="RowDataboundEventHandler"
Add this to your gridview and the handler will be:
protect void RowDataboundEventHandler(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Get value from column directly
string value = e.Row.Cells[1].Text;
// if you want to find control value
e.Row.FindControl("controlID");
}
}
Upvotes: 1
Reputation: 803
Assuming reader
is a DataTable
and without any information about what the type of data is, you can use the below. You'll have to provide more information or write the yourCustomConversion()
method yourself.
var reader = getYourData();
foreach (DataRow row in reader.Rows)
{
row["affectedColumn"] = yourCustomConversion(row["affectedColumn"]);
}
GridView1.DataSource = reader;
GridView1.DataBind();
Upvotes: 0