ASPNet 2.0 GridView question

J

Jason Huang

Hi,

In my ASPNET 2.0 C# Web form, I have a funciton BindGridView for binding
SqlDataSourceA to the GridView gvTestForm.
And in the end of the function, I would like to check if there are no rows
in the GridView then the control btnDetail is disabled.
However, this function doesn't work as what I pland.
The gvTestForm.Rows.Count respond last time's Row, not the current row count
in ths SqlDataSourceA.
What have I done wrong?
Thanks for help.


Jason



public void BindGridView()
{

this.m_strStartDate = this.ddlStartYear.SelectedItem.Text +
this.ddlStartMonth.SelectedItem.Text + this.ddlStartDay.SelectedItem.Text;
this.m_strEndDate = this.ddlEndYear.Text + this.ddlEndMonth.Text +
this.ddlEndDay.Text;
try
{
this.SqlDataSourceA.SelectParameters["prAcceptDateStart"].DefaultValue
= this.m_strStartDate;
this.SqlDataSourceA.SelectParameters["prAcceptDateEnd"].DefaultValue
= this.m_strEndDate;
this.SqlDataSourceA.SelectCommand = this.m_strSQL;
this.gvTestForm.Visible = true;
this.gvTestForm.AllowPaging = true;
this.gvTestForm.PageSize = 10;

}
catch
{
basfuncs.MessageBox(this, "Wrong Query");
}

if (gvTestForm.Rows.Count > 0)
this.btnDetail.Enabled = true;
else
this.btnDetail.Enabled = false;

}
 
E

Eliyahu Goldin

The grid is not databound yet when you check the count. Move the check into
the grid's PreRender event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ASPNET 2.0 Page_Load question 5
More problem with paging GridView 0
Gridview binding twice 4
GridView Question 1
ASPNET GridView and page question 3
GridView SelectedIndexChanged question 11
GridView 0
gridview 0

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top