473,406 Members | 2,705 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,406 software developers and data experts.

Validation to find out if datagrid has any rows

I am trying to run some validation on the on-click event of a button to check
and see whether a datagrid has any items inserted into it and if it does then
I'd like it to work as normal. However if it has no items in it then i'd like
it to display the error message below and not move forward. Here is the code
I have but it doesn't seem to work. I think i've got the wrong logic. Can
someone help me work this out.
Thanks

private void cicmdPerformSearch_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
if (this.dgSearchAddresses.Items.Count == 0)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
Context.Items["TransferAddresses"] = addresses;
Server.Transfer("../Internet/WebForm2.aspx");
}
else
{
pnlMessages.Visible = true;
this.lblMessage.Text = "You must select at least one address";
}
}

Nov 22 '05 #1
1 1554
Hi Stephen,

Do you have viewstate turned on for the datagrid or do you reload on
postback? Depending on how your viewstate is setup, I believe your .Count
would be -0- until reloaded on postback. Maybe during the initial load you
can store the .Count in a single variable in viewstate and then read that on
the cicmdPerformSearch_Click event.

-Mike S.

"Stephen" wrote:
I am trying to run some validation on the on-click event of a button to check
and see whether a datagrid has any items inserted into it and if it does then
I'd like it to work as normal. However if it has no items in it then i'd like
it to display the error message below and not move forward. Here is the code
I have but it doesn't seem to work. I think i've got the wrong logic. Can
someone help me work this out.
Thanks

private void cicmdPerformSearch_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
if (this.dgSearchAddresses.Items.Count == 0)
{
ArrayList addresses;
addresses = (ArrayList) ViewState["Addresses"];
Context.Items["TransferAddresses"] = addresses;
Server.Transfer("../Internet/WebForm2.aspx");
}
else
{
pnlMessages.Visible = true;
this.lblMessage.Text = "You must select at least one address";
}
}

Nov 22 '05 #2

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

Similar topics

1
by: Stephen | last post by:
I am trying to run some validation on the on-click event of a button to check and see whether a datagrid has any items inserted into it and if it does then I'd like it to work as normal. However if...
3
by: Stephen | last post by:
I have two datagrids on a page and each of them allow the user to add rows. On each datagrid I have validation (required field, reg expressions etc) and my problem is that I only want the...
0
by: JR | last post by:
Hello, Does anyone know how you can prevent a row full of 'null' values from being added to the datagrid when a user hits the delete key, deleting the word (null) which represents the default...
2
by: Stephen | last post by:
Hey everyone, I am trying to run some validation on the on-click event of a button to check and see whether a datagrid contains any rows inserted into it and if it does then I'd like it to work as...
1
by: Stephen | last post by:
I have two datagrids on a page and each of them allow the user to add rows. On each datagrid I have validation (required field, reg expressions etc) and my problem is that I only want the...
1
by: Kris | last post by:
Hi, I have a DataGrid where in each row has couple of text boxes and an update button. Each row is dynamically generated as the number of rows are not known ahead of time. When the user clicks the...
5
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design...
1
by: Tom | last post by:
I have seen articles saying that validating the data a user enters into a datagrid is difficult, because it is not the datagrid itself that does the validation, but rather textboxes that are in...
4
by: Aaron Smith | last post by:
Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1,...
5
by: Peter Afonin | last post by:
Hello, I'm not an expert in Javascript, so I'm seeking an advice. As I mentioned in my previous post, I use Javascript to check whether at least one checkbox in the datagrid has been checked....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.