473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ASPNet 2.0 GridView question

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;

}
Sep 21 '07 #1
1 1157
The grid is not databound yet when you check the count. Move the check into
the grid's PreRender event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Jason Huang" <Ja************@hotmail.comwrote in message
news:O5**************@TK2MSFTNGP06.phx.gbl...
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;

}


Sep 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
4
by: Chris | last post by:
Hi, I read about client callback and i have a question. Assume the option "sorting" is set in a gridview. Each time the user clicks on a fieldname, the data are sorted. My question is: are...
3
by: Gonza | last post by:
Hi group, i have a question relatred to gridview and postback (i should probably know this by now, considering i've been working with .net for a few years now, but baahh). Why could a gridview...
1
by: Barry L. Camp | last post by:
Hi all, Wondering if someone can help with a nagging problem I am having using a GridView and an ObjectDataSource. I have a simple situation where I am trying to delete a row from a table, but...
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
3
by: Jason Huang | last post by:
Hi, In my ASPNET 2.0 web form WebForm1.aspx, I have a GridView GridView1 and some other controls in front of the GridView1. There are CheckBoxes on the GridView1 also. My question is when I...
5
by: Jason Huang | last post by:
Hi, In my ASPNet 2.0 C# web application Form1.aspx, there are 1 TextBox control txtBox1, 1 Button control Btn1, and 1 GridView control GV1. I found whenever I click the Button control Btn1, then...
1
by: Cirene | last post by:
This is confusing... I have a gridview (gv1) with another gridview (gv2) inside of it. gv1 has a bunch of house listings and within each row is a group of related house pictures (gv2). I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.