473,320 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,320 software developers and data experts.

Looping through a filtered GridView

Ken
Hi All -

I have a filtered GridView. This GridView has a check box in the first
column. This check box is used to identify specific rows for delete
operations.

On the button click event I loop through the filtered GridView to identify
the selected rows and assemble some XML to be sent to a stored proc.

The problem I have is that when looping through the GridView, it doesn't
appear to recognize the filter that is correctly applied in the page. The
GridView.Rows.Count is 100 (unfiltered) when it should be 10 (filtered). The
result is that the incorrect rows are identified as being selected.

Any ideas about how I can loop through a filtered GridView to identify
selected rows?

Thanks!
Dec 22 '05 #1
7 5448
Hello,

Are you directly binding dataset to grid and then applying filter Or
using dataview to filter data and binding filterd dataview to grid?

Regards,
bhawin13

Dec 22 '05 #2
Hi kenj,

As bhawin has mentioned, how are you binding the filtered data source to
the GridView, using DataSourceControl or programmatically get a DataSet and
DataView? Based on my research, when using DataSource with filter
expression(to filer data....), the GridView.Rows.Count will be identical to
the filtered dataview's row count.... e.g:

<asp qlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:LocalNorthWind %>"
SelectCommand="SELECT [Discontinued], [ProductID],
[ProductName], [UnitPrice] FROM [Products]"
FilterExpression="Discontinued = {0}" >
<FilterParameters>
<asp:ControlParameter ControlID="Discontinued" Name="Discontinued"
PropertyName="Checked" />
</FilterParameters>
</asp qlDataSource>

Then, we I use the following code to get the GridView's current Row count:

protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Write("<br>GridView2.Rows.Count: " + GridView2.Rows.Count);
}

it'll return the correct Row count which identical to the filtered data
records (which is displayed on the page....)..

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "bhawin13" <bh******@indiatimes.com>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Subject: Re: Looping through a filtered GridView
| Date: 21 Dec 2005 21:01:02 -0800
| Organization: http://groups.google.com
| Lines: 8
| Message-ID: <11**********************@g14g2000cwa.googlegroups .com>
| References: <E9**********************************@microsoft.co m>
| NNTP-Posting-Host: 155.57.155.200
| Mime-Version: 1.0
| Content-Type: text/plain; charset="iso-8859-1"
| X-Trace: posting.google.com 1135227667 28410 127.0.0.1 (22 Dec 2005
05:01:07 GMT)
| X-Complaints-To: gr**********@google.com
| NNTP-Posting-Date: Thu, 22 Dec 2005 05:01:07 +0000 (UTC)
| In-Reply-To: <E9**********************************@microsoft.co m>
| User-Agent: G2/0.2
| X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1),gzip(gfe),gzip(gfe)
| Complaints-To: gr**********@google.com
| Injection-Info: g14g2000cwa.googlegroups.com; posting-host=155.57.155.200;
| posting-account=W_Or8A0AAAAFcoIIvCx4IwUus4o4Wqvc
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!news.glorb.com!postnews.google.com!g14g2000c wa.googlegroups.com!not-fo
r-mail
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366469
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello,
|
| Are you directly binding dataset to grid and then applying filter Or
| using dataview to filter data and binding filterd dataview to grid?
|
| Regards,
| bhawin13
|
|

Dec 22 '05 #3
Ken
I am binding the GridView to an ObjectDataSource configured as follows:
<asp:ObjectDataSource
EnablePaging="true"
SelectCountMethod="GetListCount"
StartRowIndexParameterName="currentRow"
SortParameterName="sortExpression"
MaximumRowsParameterName="pageSize"
ID="discountListDs"
runat="server"
TypeName="Discount"
SelectMethod="GetDiscountList">
<SelectParameters>
<asp:ControlParameter name="dateFilter" controlid="currentDiscounts"
PropertyName="Checked" />
<asp:ControlParameter name="regionFilter" controlid="region"
PropertyName="Value" />
</SelectParameters>
</asp:ObjectDataSource>

I am then looping through the GridView using code similar to the following:
protected void copyDiscount_ServerClick(object sender, EventArgs e)
{
CheckBox cb;
for (int i = 0; i < discountGrid.Rows.Count; i++)
{
cb = (CheckBox)discountGrid.Rows[i].FindControl("SelectedBox");
if (cb.Checked)
{
Server.Transfer("DiscountForm.aspx?EditMode=" + (int)EditMode.COPY +
"&DiscountId=" + discountGrid.Rows[i].Attributes["DiscountId"].ToString());
}
}
}

Dec 22 '05 #4
Ken
I have done a little more research. When using SelectParameters as a
mechanism for filtering, I noticed that the designated SelectMethod on the
ObjectDataSource fires more than once. This resulted in 4 calls to the
stored proc (identified in SQL Profiler) that is being executed as part of
the SelectMethod.

Any help is greatly appreciated.

Dec 22 '05 #5
Thanks for your response kenj,

So you're using ObjectDataSource with your custom data access class object.
I've just performed some tests through the MSDN objectdataource sample
object, and seems it works correct, the GridView.Rows.Count be identical
to the rows correctly displayed( one page....). Would you provide some
further code logical of your custom data access object? Since when enabling
paging for object datasource, we should makesure the SelectCountMethod
reflect the current total records count , and the selectMethod will return
the certain page of records with the same logic as "SelectCountMethod".
However, when you're using other Select parameters, I think this logic will
be broken (SelectCountMethod dosn't have such parameters as criteria), yes?

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: Looping through a filtered GridView
| thread-index: AcYHSF3JxYPwLcAIRBWk6VAeC0E/pA==
| X-WBNR-Posting-Host: 130.76.32.144
| From: =?Utf-8?B?S2Vu?= <ke**@newsgroups.nospam>
| References: <E9**********************************@microsoft.co m>
<11**********************@g14g2000cwa.googlegroups .com>
<$8**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Looping through a filtered GridView
| Date: Thu, 22 Dec 2005 14:38:02 -0800
| Lines: 8
| Message-ID: <0B**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:366675
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have done a little more research. When using SelectParameters as a
| mechanism for filtering, I noticed that the designated SelectMethod on
the
| ObjectDataSource fires more than once. This resulted in 4 calls to the
| stored proc (identified in SQL Profiler) that is being executed as part
of
| the SelectMethod.
|
| Any help is greatly appreciated.
|
|

Dec 23 '05 #6
Ken
Thanks for replying Steven. Sorry about the taking so long to respond.
Christmas vacation :)

I have provided the code you requested below. The events on the page appear
to be firing in the following patterns:
SEQUENCE OF EVENTS WHEN PAGE IS INITIALLY LOADED AFTER MENU SELECTION
Page_Load
GetContactList is called
GetListCount is called

SEQUENCE OF EVENTS WHEN SELECT PARAMETERS ARE APPLIED
GetContactList is called (regionFilter parameter is not set)
GetListCount is called (regionFilter parameter is not set)
Page_Load
GetContactList is called (regionFilter parameter has a value)
GetListCount is called (regionFilter parameter has a value)

SEQUENCE OF EVENTS WHEN DELETE BUTTON IS PRESSED
GetContactList is called (regionFilter parameter is not set)
GetListCount is called (regionFilter parameter is not set)
Page_Load
deleteContests_ServerClick (GridView contains unfiltered results)
GetContactList is called (regionFilter parameter has a value)
GetListCount is called (regionFilter parameter has a value)

public static DataSet GetDiscountList(
int pageSize
, int currentRow
, string sortExpression
, bool dateFilter
, int regionFilter
)
{
DiscountDatabase db = new DiscountDatabase();
SqlParameter[] parms = new SqlParameter[(dateFilter ? 7 : 5)];

parms[0] = new SqlParameter("@pageSize", pageSize);
if (regionFilter == 0)
{
parms[1] = new SqlParameter("@regionFilter", null);
}
else
{
parms[1] = new SqlParameter("@regionFilter", regionFilter);
}
//... set other parameters
return db.GetDataSet("getDiscountList", parms);
}
public static int GetListCount(
bool dateFilter
, int regionFilter
)
{
DiscountDatabase db = new DiscountDatabase();
SqlParameter[] parms = new SqlParameter[(dateFilter ? 6 : 4)];

parms[0] = new SqlParameter("@pageSize", int.MaxValue);
if (regionFilter == 0)
{
parms[1] = new SqlParameter("@regionFilter", null);
}
else
{
parms[1] = new SqlParameter("@regionFilter", regionFilter);
}
//... set other parameters

return (int)db.GetScaler("getDiscountList", parms);
}
public static void DeleteDiscounts(string discountList)
{
DiscountDatabase db = new DiscountDatabase();
SqlParameter[] parms = new SqlParameter[1];

parms[0] = new SqlParameter("@discountList", discountList);

db.ExecuteProcedure("DeleteDiscounts", parms);
}
Jan 3 '06 #7
Hi Kenj,

Seems the problem is data access component related or page specific. I've
justed performed some tests through a sample data access object( use
Northwind database's employee table), and I found that eveytime, the page
load (no matter initial request all sequential postback...), the
ObjectDataSource's SelectMethod and SelectCount method(if enabe paging)
will be called only once .... I print out the statement in page's output
trace ....
So will the duplicated method calls caused by some other controls or code
on the page?

Here is my test data access object class (I only use a single additional
select parameter....):
=============
/// <summary>
/// Summary description for objDS
/// </summary>
namespace Samples.AspNet.ObjectDataSource
{
//
// Northwind Employee Data Factory
//

public class NorthwindData
{

private string _connectionString;
public NorthwindData()
{
Initialize();
}
public void Initialize()
{
// Initialize data source. Use "Northwind" connection string
from configuration.

if (ConfigurationManager.ConnectionStrings["Northwind"] == null
||

ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString.Trim()
== "")
{
throw new Exception("A connection string named 'Northwind'
with a valid connection string " +
"must exist in the <connectionStrings>
configuration section for the application.");
}

_connectionString =

ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
}
// Select all employees.

public DataTable GetAllEmployees(string sortColumns, int
startRecord, int maxRecords, int eid)
{
VerifySortColumns(sortColumns);

string sqlCmd = "SELECT EmployeeID, LastName, FirstName,
Address, City, Region, PostalCode FROM Employees ";

//test code
HttpContext.Current.Trace.Warn("<br>GetAllEmployee s, eid: " +
eid);
//eid = -1;

if(eid > 0)
{
sqlCmd += " WHERE EmployeeID > @eid ";
}

if (sortColumns.Trim() == "")
sqlCmd += "ORDER BY EmployeeID";
else
sqlCmd += "ORDER BY " + sortColumns;

SqlConnection conn = new SqlConnection(_connectionString);
SqlDataAdapter da = new SqlDataAdapter(sqlCmd, conn);

if(eid > 0)
{
da.SelectCommand.Parameters.Add("@eid",SqlDbType.I nt);
da.SelectCommand.Parameters["@eid"].Value = eid;
}

DataSet ds = new DataSet();

try
{
conn.Open();

da.Fill(ds, startRecord, maxRecords, "Employees");
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return ds.Tables["Employees"];
}
public int SelectCount(int eid )
{
string sqlCmd = "SELECT COUNT(*) FROM Employees";
//test code
HttpContext.Current.Trace.Warn("<br>SelectCount, eid: " + eid);
//eid = 0;

if (eid > 0)
{
sqlCmd += " WHERE EmployeeID > @eid ";
}

SqlConnection conn = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand(sqlCmd, conn);

if (eid > 0)
{
cmd.Parameters.Add("@eid", SqlDbType.Int);
cmd.Parameters["@eid"].Value = eid;
}

int result = 0;

try
{
conn.Open();

result = (int)cmd.ExecuteScalar();
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return result;
}
//////////
// Verify that only valid columns are specified in the sort
expression to avoid a SQL Injection attack.

private void VerifySortColumns(string sortColumns)
{
if (sortColumns.ToLowerInvariant().EndsWith(" desc"))
sortColumns = sortColumns.Substring(0, sortColumns.Length -
5);

string[] columnNames = sortColumns.Split(',');

foreach (string columnName in columnNames)
{
switch (columnName.Trim().ToLowerInvariant())
{
case "employeeid":
break;
case "lastname":
break;
case "firstname":
break;
case "":
break;
default:
throw new ArgumentException("SortColumns contains
an invalid column name.");
break;
}
}
}

// Select an employee.

public DataTable GetEmployee(int EmployeeID)
{
SqlConnection conn = new SqlConnection(_connectionString);
SqlDataAdapter da =
new SqlDataAdapter("SELECT EmployeeID, LastName, FirstName,
Address, City, Region, PostalCode " +
" FROM Employees WHERE EmployeeID =
@EmployeeID", conn);
da.SelectCommand.Parameters.Add("@EmployeeID",
SqlDbType.Int).Value = EmployeeID;

DataSet ds = new DataSet();

try
{
conn.Open();

da.Fill(ds, "Employees");
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return ds.Tables["Employees"];
}

// Delete the Employee by ID.

public int DeleteEmployee(int EmployeeID)
{
SqlConnection conn = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand("DELETE FROM Employees WHERE
EmployeeID = @EmployeeID", conn);
cmd.Parameters.Add("@EmployeeID", SqlDbType.Int).Value =
EmployeeID;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return result;
}
// Update the Employee by original ID.

public int UpdateEmployee(int EmployeeID, string LastName, string
FirstName,
string Address, string City, string
Region, string PostalCode)
{

//test code
HttpContext.Current.Trace.Warn("<br>UpdateEmployee ");

if (String.IsNullOrEmpty(FirstName))
throw new ArgumentException("FirstName cannot be null or an
empty string.");
if (String.IsNullOrEmpty(LastName))
throw new ArgumentException("LastName cannot be null or an
empty string.");

if (Address == null) { Address = String.Empty; }
if (City == null) { City = String.Empty; }
if (Region == null) { Region = String.Empty; }
if (PostalCode == null) { PostalCode = String.Empty; }

SqlConnection conn = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand("UPDATE Employees " +
" SET
FirstName=@FirstName, LastName=@LastName, " +
" Address=@Address,
City=@City, Region=@Region, " +
" PostalCode=@PostalCode "
+
" WHERE
EmployeeID=@EmployeeID", conn);

cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 10).Value =
FirstName;
cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 20).Value =
LastName;
cmd.Parameters.Add("@Address", SqlDbType.VarChar, 60).Value =
Address;
cmd.Parameters.Add("@City", SqlDbType.VarChar, 15).Value = City;
cmd.Parameters.Add("@Region", SqlDbType.VarChar, 15).Value =
Region;
cmd.Parameters.Add("@PostalCode", SqlDbType.VarChar, 10).Value
= PostalCode;
cmd.Parameters.Add("@EmployeeID", SqlDbType.Int).Value =
EmployeeID;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return result;
}
// Insert an Employee.

public int InsertEmployee(string LastName, string FirstName,
string Address, string City, string
Region, string PostalCode)
{
if (String.IsNullOrEmpty(FirstName))
throw new ArgumentException("FirstName cannot be null or an
empty string.");
if (String.IsNullOrEmpty(LastName))
throw new ArgumentException("LastName cannot be null or an
empty string.");

if (Address == null) { Address = String.Empty; }
if (City == null) { City = String.Empty; }
if (Region == null) { Region = String.Empty; }
if (PostalCode == null) { PostalCode = String.Empty; }

SqlConnection conn = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand("INSERT INTO Employees " +
" (FirstName, LastName,
Address, City, Region, PostalCode) " +
" Values(@FirstName,
@LastName, @Address, @City, @Region, @PostalCode); " +
"SELECT @EmployeeID =
SCOPE_IDENTITY()", conn);

cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 10).Value =
FirstName;
cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 20).Value =
LastName;
cmd.Parameters.Add("@Address", SqlDbType.VarChar, 60).Value =
Address;
cmd.Parameters.Add("@City", SqlDbType.VarChar, 15).Value = City;
cmd.Parameters.Add("@Region", SqlDbType.VarChar, 15).Value =
Region;
cmd.Parameters.Add("@PostalCode", SqlDbType.VarChar, 10).Value
= PostalCode;
SqlParameter p = cmd.Parameters.Add("@EmployeeID",
SqlDbType.Int);
p.Direction = ParameterDirection.Output;

int newEmployeeID = 0;

try
{
conn.Open();

cmd.ExecuteNonQuery();

newEmployeeID = (int)p.Value;
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return newEmployeeID;
}

//
// Methods that support Optimistic Concurrency checks.
//

// Delete the Employee by ID.

public int DeleteEmployee(int original_EmployeeID, string
original_LastName,
string original_FirstName, string
original_Address,
string original_City, string
original_Region,
string original_PostalCode)
{
if (String.IsNullOrEmpty(original_FirstName))
throw new ArgumentException("FirstName cannot be null or an
empty string.");
if (String.IsNullOrEmpty(original_LastName))
throw new ArgumentException("LastName cannot be null or an
empty string.");

if (original_Address == null) { original_Address =
String.Empty; }
if (original_City == null) { original_City = String.Empty; }
if (original_Region == null) { original_Region = String.Empty; }
if (original_PostalCode == null) { original_PostalCode =
String.Empty; }

string sqlCmd = "DELETE FROM Employees WHERE EmployeeID =
@original_EmployeeID " +
" AND LastName = @original_LastName AND
FirstName = @original_FirstName " +
" AND Address = @original_Address AND City =
@original_City " +
" AND Region = @original_Region AND PostalCode
= @original_PostalCode";

SqlConnection conn = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand(sqlCmd, conn);

cmd.Parameters.Add("@original_EmployeeID", SqlDbType.Int).Value
= original_EmployeeID;
cmd.Parameters.Add("@original_FirstName", SqlDbType.VarChar,
10).Value = original_FirstName;
cmd.Parameters.Add("@original_LastName", SqlDbType.VarChar,
20).Value = original_LastName;
cmd.Parameters.Add("@original_Address", SqlDbType.VarChar,
60).Value = original_Address;
cmd.Parameters.Add("@original_City", SqlDbType.VarChar,
15).Value = original_City;
cmd.Parameters.Add("@original_Region", SqlDbType.VarChar,
15).Value = original_Region;
cmd.Parameters.Add("@original_PostalCode", SqlDbType.VarChar,
10).Value = original_PostalCode;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return result;
}
// Update the Employee by original ID.

public int UpdateEmployee(int EmployeeID, string LastName, string
FirstName,
string Address, string City, string
Region, string PostalCode,
int original_EmployeeID, string
original_LastName,
string original_FirstName, string
original_Address,
string original_City, string
original_Region,
string original_PostalCode)
{
if (String.IsNullOrEmpty(FirstName))
throw new ArgumentException("FirstName cannot be null or an
empty string.");
if (String.IsNullOrEmpty(LastName))
throw new ArgumentException("LastName cannot be null or an
empty string.");

if (Address == null) { Address = String.Empty; }
if (City == null) { City = String.Empty; }
if (Region == null) { Region = String.Empty; }
if (PostalCode == null) { PostalCode = String.Empty; }

if (original_Address == null) { original_Address =
String.Empty; }
if (original_City == null) { original_City = String.Empty; }
if (original_Region == null) { original_Region = String.Empty; }
if (original_PostalCode == null) { original_PostalCode =
String.Empty; }

string sqlCmd = "UPDATE Employees " +
" SET FirstName = @FirstName, LastName =
@LastName, " +
" Address = @Address, City = @City, Region =
@Region, " +
" PostalCode = @PostalCode " +
" WHERE EmployeeID = @original_EmployeeID " +
" AND LastName = @original_LastName AND
FirstName = @original_FirstName " +
" AND Address = @original_Address AND City =
@original_City " +
" AND Region = @original_Region AND PostalCode
= @original_PostalCode";

SqlConnection conn = new SqlConnection(_connectionString);
SqlCommand cmd = new SqlCommand(sqlCmd, conn);

cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 10).Value =
FirstName;
cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 20).Value =
LastName;
cmd.Parameters.Add("@Address", SqlDbType.VarChar, 60).Value =
Address;
cmd.Parameters.Add("@City", SqlDbType.VarChar, 15).Value = City;
cmd.Parameters.Add("@Region", SqlDbType.VarChar, 15).Value =
Region;
cmd.Parameters.Add("@PostalCode", SqlDbType.VarChar, 10).Value
= PostalCode;
cmd.Parameters.Add("@original_EmployeeID", SqlDbType.Int).Value
= original_EmployeeID;
cmd.Parameters.Add("@original_FirstName", SqlDbType.VarChar,
10).Value = original_FirstName;
cmd.Parameters.Add("@original_LastName", SqlDbType.VarChar,
20).Value = original_LastName;
cmd.Parameters.Add("@original_Address", SqlDbType.VarChar,
60).Value = original_Address;
cmd.Parameters.Add("@original_City", SqlDbType.VarChar,
15).Value = original_City;
cmd.Parameters.Add("@original_Region", SqlDbType.VarChar,
15).Value = original_Region;
cmd.Parameters.Add("@original_PostalCode", SqlDbType.VarChar,
10).Value = original_PostalCode;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
// Handle exception.
}
finally
{
conn.Close();
}

return result;
}

}
}
====================================
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Thread-Topic: Looping through a filtered GridView
| thread-index: AcYQgP02l4TIi5weR3GXKRzUwu9GnQ==
| X-WBNR-Posting-Host: 130.76.32.145
| From: =?Utf-8?B?S2Vu?= <ke**@newsgroups.nospam>
| References: <E9**********************************@microsoft.co m>
<11**********************@g14g2000cwa.googlegroups .com>
<$8**************@TK2MSFTNGXA02.phx.gbl>
<0B**********************************@microsoft.co m>
<NS**************@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: Looping through a filtered GridView
| Date: Tue, 3 Jan 2006 08:16:01 -0800
| Lines: 82
| Message-ID: <6F**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:368290
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks for replying Steven. Sorry about the taking so long to respond.
| Christmas vacation :)
|
| I have provided the code you requested below. The events on the page
appear
| to be firing in the following patterns:
| SEQUENCE OF EVENTS WHEN PAGE IS INITIALLY LOADED AFTER MENU SELECTION
| Page_Load
| GetContactList is called
| GetListCount is called
|
| SEQUENCE OF EVENTS WHEN SELECT PARAMETERS ARE APPLIED
| GetContactList is called (regionFilter parameter is not set)
| GetListCount is called (regionFilter parameter is not set)
| Page_Load
| GetContactList is called (regionFilter parameter has a value)
| GetListCount is called (regionFilter parameter has a value)
|
| SEQUENCE OF EVENTS WHEN DELETE BUTTON IS PRESSED
| GetContactList is called (regionFilter parameter is not set)
| GetListCount is called (regionFilter parameter is not set)
| Page_Load
| deleteContests_ServerClick (GridView contains unfiltered results)
| GetContactList is called (regionFilter parameter has a value)
| GetListCount is called (regionFilter parameter has a value)
|
| public static DataSet GetDiscountList(
| int pageSize
| , int currentRow
| , string sortExpression
| , bool dateFilter
| , int regionFilter
| )
| {
| DiscountDatabase db = new DiscountDatabase();
| SqlParameter[] parms = new SqlParameter[(dateFilter ? 7 : 5)];
|
| parms[0] = new SqlParameter("@pageSize", pageSize);
| if (regionFilter == 0)
| {
| parms[1] = new SqlParameter("@regionFilter", null);
| }
| else
| {
| parms[1] = new SqlParameter("@regionFilter", regionFilter);
| }
| //... set other parameters
|
|
| return db.GetDataSet("getDiscountList", parms);
| }
| public static int GetListCount(
| bool dateFilter
| , int regionFilter
| )
| {
| DiscountDatabase db = new DiscountDatabase();
| SqlParameter[] parms = new SqlParameter[(dateFilter ? 6 : 4)];
|
| parms[0] = new SqlParameter("@pageSize", int.MaxValue);
| if (regionFilter == 0)
| {
| parms[1] = new SqlParameter("@regionFilter", null);
| }
| else
| {
| parms[1] = new SqlParameter("@regionFilter", regionFilter);
| }
| //... set other parameters
|
| return (int)db.GetScaler("getDiscountList", parms);
| }
| public static void DeleteDiscounts(string discountList)
| {
| DiscountDatabase db = new DiscountDatabase();
| SqlParameter[] parms = new SqlParameter[1];
|
| parms[0] = new SqlParameter("@discountList", discountList);
|
| db.ExecuteProcedure("DeleteDiscounts", parms);
| }
|
|
|

Jan 5 '06 #8

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

Similar topics

3
by: Karl Roes | last post by:
Hi All, I would also like some help with form filtered differences in totals. I have a main form for the client, and a continuous subform listing client transactions. The subform can be...
1
by: Ken | last post by:
I have a form that has a command button on it to open a report. The report is based on the forms data, if it's filtered the report is filtered, if the form is showing 100 records the report is...
2
by: Spartaco | last post by:
I have a dropdown control into a page and a gridview, both are associated to two SqlDataSource controls, one of them is used to fill the DropDownControl, that is meant to be a filter over the query...
3
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: ...
1
by: Greg Smith | last post by:
I would like to display the filtered record count for a datasource used to populate a gridview. I would like to change it every time the filter is changed. Is there a way to do this? Any...
0
by: Ironr4ge | last post by:
Hi everyone, By the rate its going it want be long till I start growing gray hair... but anyway.. to come to the point... I am trying to open the form "Languages" with a diffrent record...
4
by: Ironr4ge | last post by:
Hi everyone, I am trying to open the form "Languages" with a diffrent record source to the "Contacts" form where I conducted the search or filter... . I was wondering whether there was a vba...
3
by: newbieAl | last post by:
I have a stored procedure in mysql and I am calling it via a method and objectdatasource. I have two select methods. One that gets a list of employees and the other that gets one specific employee by...
6
by: ccookson | last post by:
The following code is part of a button (on click) that places a check (true) in a filtered subform. The subform is a set of continuous forms. The checks are placed but it gives an error message...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.