473,583 Members | 4,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.C ount 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 5462
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 DataSourceContr ol or programmaticall y get a DataSet and
DataView? Based on my research, when using DataSource with filter
expression(to filer data....), the GridView.Rows.C ount will be identical to
the filtered dataview's row count.... e.g:

<asp qlDataSource ID="SqlDataSour ce2" runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:LocalNorthWi nd %>"
SelectCommand=" SELECT [Discontinued], [ProductID],
[ProductName], [UnitPrice] FROM [Products]"
FilterExpressio n="Discontinu ed = {0}" >
<FilterParamete rs>
<asp:ControlPar ameter ControlID="Disc ontinued" Name="Discontin ued"
PropertyName="C hecked" />
</FilterParameter s>
</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******@india times.com>
| Newsgroups: microsoft.publi c.dotnet.framew ork.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************ **********@g14g 2000cwa.googleg roups.com>
| References: <E9************ *************** *******@microso ft.com>
| 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**********@go ogle.com
| NNTP-Posting-Date: Thu, 22 Dec 2005 05:01:07 +0000 (UTC)
| In-Reply-To: <E9************ *************** *******@microso ft.com>
| 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**********@go ogle.com
| Injection-Info: g14g2000cwa.goo glegroups.com; posting-host=155.57.155 .200;
| posting-account=W_Or8A0 AAAAFcoIIvCx4Iw Uus4o4Wqvc
| Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!ne wsfeed00.sul.t-online.de!t-onli
ne.de!news.glor b.com!postnews. google.com!g14g 2000cwa.googleg roups.com!not-fo
r-mail
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3664 69
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 ObjectDataSourc e configured as follows:
<asp:ObjectData Source
EnablePaging="t rue"
SelectCountMeth od="GetListCoun t"
StartRowIndexPa rameterName="cu rrentRow"
SortParameterNa me="sortExpress ion"
MaximumRowsPara meterName="page Size"
ID="discountLis tDs"
runat="server"
TypeName="Disco unt"
SelectMethod="G etDiscountList" >
<SelectParamete rs>
<asp:ControlPar ameter name="dateFilte r" controlid="curr entDiscounts"
PropertyName="C hecked" />
<asp:ControlPar ameter name="regionFil ter" controlid="regi on"
PropertyName="V alue" />
</SelectParameter s>
</asp:ObjectDataS ource>

I am then looping through the GridView using code similar to the following:
protected void copyDiscount_Se rverClick(objec t sender, EventArgs e)
{
CheckBox cb;
for (int i = 0; i < discountGrid.Ro ws.Count; i++)
{
cb = (CheckBox)disco untGrid.Rows[i].FindControl("S electedBox");
if (cb.Checked)
{
Server.Transfer ("DiscountForm. aspx?EditMode=" + (int)EditMode.C OPY +
"&DiscountI d=" + discountGrid.Ro ws[i].Attributes["DiscountId "].ToString());
}
}
}

Dec 22 '05 #4
Ken
I have done a little more research. When using SelectParameter s as a
mechanism for filtering, I noticed that the designated SelectMethod on the
ObjectDataSourc e 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 ObjectDataSourc e 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.C ount 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 SelectCountMeth od
reflect the current total records count , and the selectMethod will return
the certain page of records with the same logic as "SelectCountMet hod".
However, when you're using other Select parameters, I think this logic will
be broken (SelectCountMet hod 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: AcYHSF3JxYPwLcA IRBWk6VAeC0E/pA==
| X-WBNR-Posting-Host: 130.76.32.144
| From: =?Utf-8?B?S2Vu?= <ke**@newsgroup s.nospam>
| References: <E9************ *************** *******@microso ft.com>
<11************ **********@g14g 2000cwa.googleg roups.com>
<$8************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: Looping through a filtered GridView
| Date: Thu, 22 Dec 2005 14:38:02 -0800
| Lines: 8
| Message-ID: <0B************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GXA01.phx.gbl!T K2MSFTNGXA03.ph x.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3666 75
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| I have done a little more research. When using SelectParameter s as a
| mechanism for filtering, I noticed that the designated SelectMethod on
the
| ObjectDataSourc e 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
)
{
DiscountDatabas e db = new DiscountDatabas e();
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
)
{
DiscountDatabas e db = new DiscountDatabas e();
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.GetScal er("getDiscount List", parms);
}
public static void DeleteDiscounts (string discountList)
{
DiscountDatabas e db = new DiscountDatabas e();
SqlParameter[] parms = new SqlParameter[1];

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

db.ExecuteProce dure("DeleteDis counts", 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
ObjectDataSourc e'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. ObjectDataSourc e
{
//
// Northwind Employee Data Factory
//

public class NorthwindData
{

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

if (ConfigurationM anager.Connecti onStrings["Northwind"] == null
||

ConfigurationMa nager.Connectio nStrings["Northwind"].ConnectionStri ng.Trim()
== "")
{
throw new Exception("A connection string named 'Northwind'
with a valid connection string " +
"must exist in the <connectionStri ngs>
configuration section for the application.");
}

_connectionStri ng =

ConfigurationMa nager.Connectio nStrings["Northwind"].ConnectionStri ng;
}
// Select all employees.

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

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

//test code
HttpContext.Cur rent.Trace.Warn ("<br>GetAllEmp loyees, eid: " +
eid);
//eid = -1;

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

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

SqlConnection conn = new SqlConnection(_ connectionStrin g);
SqlDataAdapter da = new SqlDataAdapter( sqlCmd, conn);

if(eid > 0)
{
da.SelectComman d.Parameters.Ad d("@eid",SqlDbT ype.Int);
da.SelectComman d.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.Cur rent.Trace.Warn ("<br>SelectCou nt, eid: " + eid);
//eid = 0;

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

SqlConnection conn = new SqlConnection(_ connectionStrin g);
SqlCommand cmd = new SqlCommand(sqlC md, conn);

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

int result = 0;

try
{
conn.Open();

result = (int)cmd.Execut eScalar();
}
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 VerifySortColum ns(string sortColumns)
{
if (sortColumns.To LowerInvariant( ).EndsWith(" desc"))
sortColumns = sortColumns.Sub string(0, sortColumns.Len gth -
5);

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

foreach (string columnName in columnNames)
{
switch (columnName.Tri m().ToLowerInva riant())
{
case "employeeid ":
break;
case "lastname":
break;
case "firstname" :
break;
case "":
break;
default:
throw new ArgumentExcepti on("SortColumn s contains
an invalid column name.");
break;
}
}
}

// Select an employee.

public DataTable GetEmployee(int EmployeeID)
{
SqlConnection conn = new SqlConnection(_ connectionStrin g);
SqlDataAdapter da =
new SqlDataAdapter( "SELECT EmployeeID, LastName, FirstName,
Address, City, Region, PostalCode " +
" FROM Employees WHERE EmployeeID =
@EmployeeID", conn);
da.SelectComman d.Parameters.Ad d("@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(_ connectionStrin g);
SqlCommand cmd = new SqlCommand("DEL ETE FROM Employees WHERE
EmployeeID = @EmployeeID", conn);
cmd.Parameters. Add("@EmployeeI D", SqlDbType.Int). Value =
EmployeeID;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQ uery();
}
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.Cur rent.Trace.Warn ("<br>UpdateEmp loyee");

if (String.IsNullO rEmpty(FirstNam e))
throw new ArgumentExcepti on("FirstName cannot be null or an
empty string.");
if (String.IsNullO rEmpty(LastName ))
throw new ArgumentExcepti on("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(_ connectionStrin g);
SqlCommand cmd = new SqlCommand("UPD ATE Employees " +
" SET
FirstName=@Firs tName, LastName=@LastN ame, " +
" Address=@Addres s,
City=@City, Region=@Region, " +
" PostalCode=@Pos talCode "
+
" WHERE
EmployeeID=@Emp loyeeID", conn);

cmd.Parameters. Add("@FirstName ", SqlDbType.VarCh ar, 10).Value =
FirstName;
cmd.Parameters. Add("@LastName" , SqlDbType.VarCh ar, 20).Value =
LastName;
cmd.Parameters. Add("@Address", SqlDbType.VarCh ar, 60).Value =
Address;
cmd.Parameters. Add("@City", SqlDbType.VarCh ar, 15).Value = City;
cmd.Parameters. Add("@Region", SqlDbType.VarCh ar, 15).Value =
Region;
cmd.Parameters. Add("@PostalCod e", SqlDbType.VarCh ar, 10).Value
= PostalCode;
cmd.Parameters. Add("@EmployeeI D", SqlDbType.Int). Value =
EmployeeID;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQ uery();
}
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.IsNullO rEmpty(FirstNam e))
throw new ArgumentExcepti on("FirstName cannot be null or an
empty string.");
if (String.IsNullO rEmpty(LastName ))
throw new ArgumentExcepti on("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(_ connectionStrin g);
SqlCommand cmd = new SqlCommand("INS ERT INTO Employees " +
" (FirstName, LastName,
Address, City, Region, PostalCode) " +
" Values(@FirstNa me,
@LastName, @Address, @City, @Region, @PostalCode); " +
"SELECT @EmployeeID =
SCOPE_IDENTITY( )", conn);

cmd.Parameters. Add("@FirstName ", SqlDbType.VarCh ar, 10).Value =
FirstName;
cmd.Parameters. Add("@LastName" , SqlDbType.VarCh ar, 20).Value =
LastName;
cmd.Parameters. Add("@Address", SqlDbType.VarCh ar, 60).Value =
Address;
cmd.Parameters. Add("@City", SqlDbType.VarCh ar, 15).Value = City;
cmd.Parameters. Add("@Region", SqlDbType.VarCh ar, 15).Value =
Region;
cmd.Parameters. Add("@PostalCod e", SqlDbType.VarCh ar, 10).Value
= PostalCode;
SqlParameter p = cmd.Parameters. Add("@EmployeeI D",
SqlDbType.Int);
p.Direction = ParameterDirect ion.Output;

int newEmployeeID = 0;

try
{
conn.Open();

cmd.ExecuteNonQ uery();

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_Employ eeID, string
original_LastNa me,
string original_FirstN ame, string
original_Addres s,
string original_City, string
original_Region ,
string original_Postal Code)
{
if (String.IsNullO rEmpty(original _FirstName))
throw new ArgumentExcepti on("FirstName cannot be null or an
empty string.");
if (String.IsNullO rEmpty(original _LastName))
throw new ArgumentExcepti on("LastName cannot be null or an
empty string.");

if (original_Addre ss == null) { original_Addres s =
String.Empty; }
if (original_City == null) { original_City = String.Empty; }
if (original_Regio n == null) { original_Region = String.Empty; }
if (original_Posta lCode == null) { original_Postal Code =
String.Empty; }

string sqlCmd = "DELETE FROM Employees WHERE EmployeeID =
@original_Emplo yeeID " +
" AND LastName = @original_LastN ame AND
FirstName = @original_First Name " +
" AND Address = @original_Addre ss AND City =
@original_City " +
" AND Region = @original_Regio n AND PostalCode
= @original_Posta lCode";

SqlConnection conn = new SqlConnection(_ connectionStrin g);
SqlCommand cmd = new SqlCommand(sqlC md, conn);

cmd.Parameters. Add("@original_ EmployeeID", SqlDbType.Int). Value
= original_Employ eeID;
cmd.Parameters. Add("@original_ FirstName", SqlDbType.VarCh ar,
10).Value = original_FirstN ame;
cmd.Parameters. Add("@original_ LastName", SqlDbType.VarCh ar,
20).Value = original_LastNa me;
cmd.Parameters. Add("@original_ Address", SqlDbType.VarCh ar,
60).Value = original_Addres s;
cmd.Parameters. Add("@original_ City", SqlDbType.VarCh ar,
15).Value = original_City;
cmd.Parameters. Add("@original_ Region", SqlDbType.VarCh ar,
15).Value = original_Region ;
cmd.Parameters. Add("@original_ PostalCode", SqlDbType.VarCh ar,
10).Value = original_Postal Code;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQ uery();
}
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_Employ eeID, string
original_LastNa me,
string original_FirstN ame, string
original_Addres s,
string original_City, string
original_Region ,
string original_Postal Code)
{
if (String.IsNullO rEmpty(FirstNam e))
throw new ArgumentExcepti on("FirstName cannot be null or an
empty string.");
if (String.IsNullO rEmpty(LastName ))
throw new ArgumentExcepti on("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_Addre ss == null) { original_Addres s =
String.Empty; }
if (original_City == null) { original_City = String.Empty; }
if (original_Regio n == null) { original_Region = String.Empty; }
if (original_Posta lCode == null) { original_Postal Code =
String.Empty; }

string sqlCmd = "UPDATE Employees " +
" SET FirstName = @FirstName, LastName =
@LastName, " +
" Address = @Address, City = @City, Region =
@Region, " +
" PostalCode = @PostalCode " +
" WHERE EmployeeID = @original_Emplo yeeID " +
" AND LastName = @original_LastN ame AND
FirstName = @original_First Name " +
" AND Address = @original_Addre ss AND City =
@original_City " +
" AND Region = @original_Regio n AND PostalCode
= @original_Posta lCode";

SqlConnection conn = new SqlConnection(_ connectionStrin g);
SqlCommand cmd = new SqlCommand(sqlC md, conn);

cmd.Parameters. Add("@FirstName ", SqlDbType.VarCh ar, 10).Value =
FirstName;
cmd.Parameters. Add("@LastName" , SqlDbType.VarCh ar, 20).Value =
LastName;
cmd.Parameters. Add("@Address", SqlDbType.VarCh ar, 60).Value =
Address;
cmd.Parameters. Add("@City", SqlDbType.VarCh ar, 15).Value = City;
cmd.Parameters. Add("@Region", SqlDbType.VarCh ar, 15).Value =
Region;
cmd.Parameters. Add("@PostalCod e", SqlDbType.VarCh ar, 10).Value
= PostalCode;
cmd.Parameters. Add("@original_ EmployeeID", SqlDbType.Int). Value
= original_Employ eeID;
cmd.Parameters. Add("@original_ FirstName", SqlDbType.VarCh ar,
10).Value = original_FirstN ame;
cmd.Parameters. Add("@original_ LastName", SqlDbType.VarCh ar,
20).Value = original_LastNa me;
cmd.Parameters. Add("@original_ Address", SqlDbType.VarCh ar,
60).Value = original_Addres s;
cmd.Parameters. Add("@original_ City", SqlDbType.VarCh ar,
15).Value = original_City;
cmd.Parameters. Add("@original_ Region", SqlDbType.VarCh ar,
15).Value = original_Region ;
cmd.Parameters. Add("@original_ PostalCode", SqlDbType.VarCh ar,
10).Value = original_Postal Code;

int result = 0;

try
{
conn.Open();

result = cmd.ExecuteNonQ uery();
}
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: AcYQgP02l4TIi5w eR3GXKRzUwu9GnQ ==
| X-WBNR-Posting-Host: 130.76.32.145
| From: =?Utf-8?B?S2Vu?= <ke**@newsgroup s.nospam>
| References: <E9************ *************** *******@microso ft.com>
<11************ **********@g14g 2000cwa.googleg roups.com>
<$8************ **@TK2MSFTNGXA0 2.phx.gbl>
<0B************ *************** *******@microso ft.com>
<NS************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: Looping through a filtered GridView
| Date: Tue, 3 Jan 2006 08:16:01 -0800
| Lines: 82
| Message-ID: <6F************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3682 90
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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
| )
| {
| DiscountDatabas e db = new DiscountDatabas e();
| 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
| )
| {
| DiscountDatabas e db = new DiscountDatabas e();
| 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.GetScal er("getDiscount List", parms);
| }
| public static void DeleteDiscounts (string discountList)
| {
| DiscountDatabas e db = new DiscountDatabas e();
| SqlParameter[] parms = new SqlParameter[1];
|
| parms[0] = new SqlParameter("@ discountList", discountList);
|
| db.ExecuteProce dure("DeleteDis counts", parms);
| }
|
|
|

Jan 5 '06 #8

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

Similar topics

3
1464
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 filtered by several fields. I have set up several text boxes which programatically show various OnCurrent subtotal details depending on the filtered...
1
5411
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 showing the same 100 records, etc. I want to create another command button which exports to excel, in the same manner above. Whether the form is...
2
1508
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 of the other SqlDatasource associated to the grid. This works fine, whenever I choose an item in the dropdown combo, I get a filtered grid. I...
3
3444
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: Access 2002 front-end using SQL Server 2000 (MSDE actually) via ADP/ADE Access Data Project.
1
1589
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 help is greatly appreciated.
0
1671
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 source to the "Contacts" form where I conducted the search or filter... . I was wondering whether there was a simple vba code to select ONLY ALL ...
4
2924
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 code to select ONLY ALL FILTERED records of my first form or the "Contacts" and open this filtered set of records in my "Languages" form. I have a...
3
2145
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 passing the employee id via a parameter. I have two gridviews, one for displaying all employees and one for displaying one employee record. The...
6
2150
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 that it can’t go to the next record. When I try to step through it, a check is placed in the first record but errors out before it starts to loop? x =...
0
7894
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8179
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6578
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5700
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3816
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1431
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1155
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.