| | |
programmaticly alter the command text of a sqldatasource???anyone?
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2008
Posts: 34
Reputation:
Solved Threads: 0
I have a simple sqlDataSource that populates a GridView control
Nothing out of the ordinary here.
The problem is that my client wants to be able to click a button and refine the querry by only showing certain records instead of all of them. Can i do this programmaticaly? Can I programaidically change the commandtext so that it says :
SELECT customerID, lname, fname, dateNow FROM dbo.customers WHERE rep is null> ORDER BY lname ASC
I beleive that i can but im unsure of what the proper syntax is. Remember, I want the gridview to display all records by defalut and only filter them as the result of some event such as a button click.
Thanks in advance.
Rick Pace
Nothing out of the ordinary here.
ASP.NET Syntax (Toggle Plain Text)
<asp:SqlDataSource ID="personalInfoSource" runat="server" ConnectionString="<%$ appSettings:Maya%>" SelectCommand="SELECT customerID, lname, fname, dateNow FROM dbo.customers ORDER BY lname ASC"> </asp:SqlDataSource> <asp:GridView ID="names" runat="server" Width="280px" DataSourceID="personalInfoSource" AutoGenerateColumns="False" DataKeyNames="customerID" AllowSorting="True"> <RowStyle BackColor="#FFBA00" Font-Names="arial" ForeColor="#26354a" /> <AlternatingRowStyle BackColor="#D3DCE6" Font-Names="arial" ForeColor="#26354a"/> <HeaderStyle BackColor="#D3DCE6" ForeColor="#26354a" Font-Names="arial" /> <Columns> <asp:BoundField DataField="customerID" HeaderText="Id" SortExpression="customerID"/> <asp:BoundField DataField="lname" HeaderText="Last Name" /> <asp:BoundField DataField="fname" HeaderText="First Name" /> <asp:BoundField DataField="dateNow" HeaderText="Id" Visible="false"/> <asp:CommandField ShowSelectButton="true" ButtonType="Button" SelectText="Select" ItemStyle-HorizontalAlign="left" HeaderText="Details" > <ItemStyle HorizontalAlign="Left" /> </asp:CommandField> </Columns> </asp:GridView>
The problem is that my client wants to be able to click a button and refine the querry by only showing certain records instead of all of them. Can i do this programmaticaly? Can I programaidically change the commandtext so that it says :
SELECT customerID, lname, fname, dateNow FROM dbo.customers WHERE rep is null> ORDER BY lname ASC
I beleive that i can but im unsure of what the proper syntax is. Remember, I want the gridview to display all records by defalut and only filter them as the result of some event such as a button click.
Thanks in advance.
Rick Pace
Last edited by Ezzaral; Oct 30th, 2009 at 4:15 pm. Reason: Snipped url. Please restrict such links to your site-wide user signature, which can be edited from the user control panel.
•
•
Join Date: Jun 2009
Posts: 442
Reputation:
Solved Threads: 82
0
#2 34 Days Ago
Try like this.
ASP.NET Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlDataSource1.SelectCommand = "SELECT customerID, lname, fname, dateNow FROM dbo.customers ORDER BY lname ASC"; } } protected void SqlDataSource1_Init(object sender, EventArgs e) { SqlDataSource1.SelectCommand = String.Empty; } protected void Button1_Click(object sender, EventArgs e) { SqlDataSource1.SelectCommand = "SELECT customerID, lname, fname, dateNow FROM dbo.customers WHERE rep is null ORDER BY lname ASC"; }
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Editing Registry Keys
- Next Thread: SqlDateTime Overflow Error
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos application asp asp.net bc30451 bottomasp.net box browser button c# c#gridviewcolumn checkbox click commonfunctions confirmationcodegeneration css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fileuploader fill flash form formatdecimal forms formview grid gridview gudi homeedition hosting iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security select silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos view virtualdirectory vista visualstudio web webapplications webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers





