Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.Net/c#: Using Query string in Gridview paging

Posted on 2008-06-12
12
Medium Priority
?
8,207 Views
Last Modified: 2013-12-17
I want to use Query string  in Grid view paging. So when moving from one page to another, I want  to pass the input parameters from  Query string to the datasoure instead of passing it directly from the text box.
<tr>
		<td class="copycontact">First Name:</td>
		<td>
		 <asp:TextBox ID="txtFirstName" runat="server" TabIndex="1" MaxLength="20" /><asp:Label ID="Req1" runat="server" CssClass="Required" Text="*" />
		 <asp:RequiredFieldValidator      CssClass="rfv" ID="vldFirstNameReq" runat="server" ControlToValidate="txtFirstName" ErrorMessage="First Name is required." Display="None" />
		 <asp:RegularExpressionValidator  CssClass="rfv" ID="vldFirstNameReqEx" runat="server" ControlToValidate="txtFirstName" ErrorMessage="Invalid First Name Format." ValidationExpression="^[a-zA-Z.\s]{2,20}$" Display="None" />
		</td>
	   </tr>
	   <tr>
		<td class="copycontact">Last Name:</td>
		<td>
		 <asp:TextBox ID="txtLastName" runat="server" TabIndex="2" MaxLength="30" /><asp:Label ID="Req2" runat="server" CssClass="Required" Text="*"/>
		 <asp:RequiredFieldValidator CssClass="rfv" ID="vldLastNameReq" runat="server" ControlToValidate="txtLastName" ErrorMessage="Last Name is required." Display="None" />
		 <asp:RegularExpressionValidator  CssClass="rfv" ID="vldLastNameReqEx" runat="server" ControlToValidate="txtLastName" ErrorMessage="Invalid Last Name Format." ValidationExpression="^[a-zA-Z-'.\s]{2,30}$" Display="None" />
		</td>
	   </tr>
 
<table width="563" border="0" cellpadding="0" cellspacing="0">
	   <tr>
		<td colspan="2">
		 <asp:GridView ID="grdFindMembers"
			 runat="server"
			 AutoGenerateColumns="False"
			 AllowPaging="True"
			 AllowSorting="True"
			 EnableViewState="False"
			 PageSize="15"
			 Width="500px"
			 OnSorting="gridView_Sorting"
			 OnPageIndexChanging="grdFindMembers_PageIndexChanging"
			 EmptyDataText="There are no members matching this search criteria.">
		  <Columns>
		   <asp:HyperLinkField HeaderText="First Name" SortExpression="FirstName" DataTextField="FirstName" DataNavigateUrlFields="IPCode"
			   NavigateUrl="~/member/AccountSummary.aspx" DataNavigateUrlFormatString="~/member/AccountSummary.aspx?MemberID={0}" />
		   <asp:HyperLinkField HeaderText="Last Name" SortExpression="LastName" DataTextField="LastName" DataNavigateUrlFields="IPCode"
			   NavigateUrl="~/member/AccountSummary.aspx" DataNavigateUrlFormatString="~/member/AccountSummary.aspx?MemberID={0}" />
		   <asp:HyperLinkField HeaderText="ZipCode" SortExpression="ZipCode" DataTextField="ZipCode" DataNavigateUrlFields="IPCode"
			   NavigateUrl="~/member/AccountSummary.aspx" DataNavigateUrlFormatString="~/member/AccountSummary.aspx?MemberID={0}" />
		   <asp:HyperLinkField HeaderText="E-Mail" SortExpression="Email" DataTextField="Email" DataNavigateUrlFields="IPCode"
			   NavigateUrl="~/member/AccountSummary.aspx" DataNavigateUrlFormatString="~/member/AccountSummary.aspx?MemberID={0}" />
		  </Columns>
		  <PagerSettings Position="Top" />
		 </asp:GridView>
		 &nbsp;
		 <asp:Label ID="lblHiddenText" runat="server" EnableViewState="False"></asp:Label>
		</td>
	   </tr>
	  </table>

Open in new window

0
Comment
Question by:meinhoona
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 

Author Comment

by:meinhoona
ID: 21773225
I hav edoubled the points.........
0
 
LVL 6

Expert Comment

by:cottsak
ID: 21775080
i would suggest not to try and do this. too many controls manage paging without you having to develop the functionality. try another grid, like Telerik's RadGrid - http://www.telerik.com/products/aspnet-ajax/controls/grid/overview.aspx
0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 21777130
if your datagrid(I think you should have) is binding to a datasource, you can add a parameter in your SQL, e.g:
SelectCommand="SELECT * FROM [table] WHERE (platform7alarm.agentIP = @agent_ip) ">
            <SelectParameters>
                <asp:QueryStringParameter Name="agent_ip" QueryStringField="agent_ip" />
            </SelectParameters>

In the example, a parameter agent_ip is defined, and the value is from QueryString.
Good luck.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:meinhoona
ID: 21780703
rendaduiyan:
I am passing input parameters to my stored procedure in my c# code. How would I use input parameters then?
0
 

Author Comment

by:meinhoona
ID: 21782727
rendaduiyan:
I am passing input parameters to my stored procedure in my c# code. How would I use QueryString as input parameters then? Give me some sample
0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 21800100
I assumed you know how to declare a stored procedure in ADO.NET.
So here is it:
when you define a sqlcommand object, you can add parameters as needed:
command.CommandType = CommandType.StoredProcedure;

command.Parameters.Add("agent_ip",  this.Request["agent_ip"]);

...


0
 

Author Comment

by:meinhoona
ID: 21826138
Its returning null value
string strFName = this.Request["strFN"];

Open in new window

0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 21843207
what's request URL? are your parameters in HTTP request correct?
pls show me your URL.
0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 21843213
sorry for the wrong guide. try this:
Request.Params["strFN"]
0
 

Author Comment

by:meinhoona
ID: 21851016
May be I am not clear enough., I am not using http request to pass variables to another page.

I just want to retain the value of my variable after the postback.
0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 21853247
let's make it clear.
in your first page, some button callback:

Response.Redirect(http://localhost/default1.aspx?strFN='str1")

and your IE you redirect to
http://localhost/default1.aspx?strFN='str1"

so in your default1.aspx cs codes,  e.g:
Page_Load(...)
{
     //you can print the request parameter out:
     this.Label1.text = Request.Params["strFN"];
}
0
 

Accepted Solution

by:
meinhoona earned 0 total points
ID: 21856588
No, I have  few text boxes acting as search criteria and populate the GridView. I want to retain these search criteria in temp variables so that when  I do pagination on the same  criteria, it would retrieve search criteria from the temp variables instead of the text boxes in order to maintain integrity of the data.
0

Featured Post

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question