T
Tomasz
Hello Developers,
Here is interesting problem I just came across: how do I wire a GridView
control programmatically?
Here is my sample code using Object Data Source:
protected void Page_Load(object sender, EventArgs e)
{
ObjectDataSource ods = new ObjectDataSource("MyTestTableAdapter",
"GetData");
GridView1.DataSource = ods;
GridView1.DataBind();
}
My GridView1 has auto generated Edit and Delete buttons, and of course, they
do not work. An attempt to modify data causes "The GridView 'GridView1'
fired event RowEditing which wasn't handled" exception.
Ok, I know that it would not update anyway, since UpdateMethod and
UpdateParameters properties are not set, but it seems that it fails before
even trying.
The same control wired using a designer (DataSourceID property) behaves
differently, that is: text boxes are being rendered, "Edit" button change to
"Cancel" and so on.
It almost seems that it is not possible to achieve the same effect
programmatically *without handling all the required events*.
Please prove me if I am wrong. I hope I am wrong, and it is not a sign a new
paradigm in MS component development: use a designer or you are screwed.
Thank you,
Tomasz
**Note: I know how to bind GridView1 programatically using templates and
handling all the events like RowEditing or RowDeleting.
Here is interesting problem I just came across: how do I wire a GridView
control programmatically?
Here is my sample code using Object Data Source:
protected void Page_Load(object sender, EventArgs e)
{
ObjectDataSource ods = new ObjectDataSource("MyTestTableAdapter",
"GetData");
GridView1.DataSource = ods;
GridView1.DataBind();
}
My GridView1 has auto generated Edit and Delete buttons, and of course, they
do not work. An attempt to modify data causes "The GridView 'GridView1'
fired event RowEditing which wasn't handled" exception.
Ok, I know that it would not update anyway, since UpdateMethod and
UpdateParameters properties are not set, but it seems that it fails before
even trying.
The same control wired using a designer (DataSourceID property) behaves
differently, that is: text boxes are being rendered, "Edit" button change to
"Cancel" and so on.
It almost seems that it is not possible to achieve the same effect
programmatically *without handling all the required events*.
Please prove me if I am wrong. I hope I am wrong, and it is not a sign a new
paradigm in MS component development: use a designer or you are screwed.
Thank you,
Tomasz
**Note: I know how to bind GridView1 programatically using templates and
handling all the events like RowEditing or RowDeleting.