Hello Andrew,
I am not sure if I understand the question correctly. Did you mean "the
page is loaded for the first time (not PostBack)" by "when not IsPostBack"?
Can I understand the question as: How to change the EditIndex property to
the last row in the GridView when the page is loaded for the first time,
without binding to the data source twice?
If my understanding is correct, we can accomplish it in this way:
In the Page_Load event handler, we add the code:
if (!IsPostBack)
{
BindGridView()
}
In the implementation of BindGridView(): (note my comments)
void BindGridView()
{
DataTable dt = GetDataTable(); // get the data source for the gridview as a
DataTable object
GridView1.DataSource = dt; // bind the data source to the gridview
int lastRowIndex = dt.Rows.Count - 1; // I suppose that no paging on the
gridview. If there is paging, we need to adjust the lastRowIndex value
accordingly.
GridView1.EditIndex = lastRowIndex; // set the edit index.
GridView1.DataBind(); // bind data
}
In this way, the edit index can be set in one data binding procedure when
the page is loaded (with no IsPostBack)
Please have a try and let me know if it works for you.
If you have any other concerns or need anything else, please feel free to
let me know.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document:
http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.