so I have this asp.net application that displays a grid of data. I want the user to be able to click anywhere on any row of that grid to start editing that row; something like data entry on a spreadsheet, but a little more controlled. dotNet 2.0 introduced a new control "gridview" to replace whatever else was used before. the event that gridview has that I want to use to trigger going into edit mode is SelectedIndexChanged - seems like a simple way to ID the row of interest and work on it. "seems" is the key word, because actually they made it hard to fire the event if you want to do anything different from the (ugly) way the control designers premade for you...
what they want you to do is use the "AutoGenerateEditButton" property to do the magic. funny they call it AutoGenerateEdit "Button" because it makes a URL looking link on the grid - not a button! then when you edit in the grid things jump around to fit the new fields that pop into the cells. looks awful.
so what you have to do to fake it out (which I'd rather not have to do, but there you go) was revealed on a google group search here
the trick is in Page_Load to add this code:
for (int i = 0; i++)
{
GridView1.Rows[i].Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(GridView1, "Select$" + i));
}
(sorry I haven't figured how to make code format right under html yet).
also in the .aspx <%@ Page... %>directive you have to add a property not shown in VS:
EnableEventValidation="False"
it works, but yuck! next, can I tackle edit mode?...
No comments:
Post a Comment