Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 10, 2012 01:24 PM by evello880
Participant
965 Points
732 Posts
Apr 10, 2012 11:17 AM|LINK
i have a gridview on my page. I want to query the database based on custom value:
this is my sqldatasource in designview for my gridview:-
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT s.fname, s.lname, s.rollno FROM Students
WHERE s.rollno='20' //this must be my choice "> </asp:SqlDataSource>
Contributor
6395 Points
1182 Posts
Apr 10, 2012 11:30 AM|LINK
Use select parameters:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT s.fname, s.lname, s.rollno FROM Students WHERE s.rollno=@RollNo "> <SelectParameters> <asp:Parameter Name="RollNo" DefaultValue="20"/> </SelectParameters> </asp:SqlDataSource>
Apr 10, 2012 12:19 PM|LINK
What I want is there should be a textbox for entering value and it should be picked up by the query. is this possible?
Apr 10, 2012 12:22 PM|LINK
Yes, you could use a ControlParameter for this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT s.fname, s.lname, s.rollno FROM Students WHERE s.rollno=@RollNo "> <SelectParameters> <asp:ControlParameter Name="RollNo" ControlID="txt" PropertyName="Text" DefaultValue="20" /> </SelectParameters> </asp:SqlDataSource>
<asp:TextBox ID="txt" runat="server" />
2396 Points
661 Posts
Apr 10, 2012 12:24 PM|LINK
<asp:SqlDataSource ID="sdsMMSPts" runat="server" ConnectionString="<%$ ConnectionStrings:mmsptsConnectionString %>" SelectCommand="SELECT [Recommended], [PatientId] FROM [Patients] WHERE ([PatientId] = @PatientId)"> <SelectParameters> <asp:ControlParameter ControlID="txtAcctNo" Name="PatientId" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource>
Member
226 Points
75 Posts
Apr 10, 2012 01:24 PM|LINK
http://www.ezzylearning.com/tutorial.aspx?tid=2397431
ogsim07
Participant
965 Points
732 Posts
how to use custom values in gridview query?
Apr 10, 2012 11:17 AM|LINK
i have a gridview on my page. I want to query the database based on custom value:
this is my sqldatasource in designview for my gridview:-
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT s.fname, s.lname, s.rollno
FROM Students
WHERE s.rollno='20' //this must be my choice
">
</asp:SqlDataSource>
mm10
Contributor
6395 Points
1182 Posts
Re: how to use custom values in gridview query?
Apr 10, 2012 11:30 AM|LINK
Use select parameters:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT s.fname, s.lname, s.rollno
FROM Students WHERE s.rollno=@RollNo
">
<SelectParameters>
<asp:Parameter Name="RollNo" DefaultValue="20"/>
</SelectParameters>
</asp:SqlDataSource>
ogsim07
Participant
965 Points
732 Posts
Re: how to use custom values in gridview query?
Apr 10, 2012 12:19 PM|LINK
What I want is there should be a textbox for entering value and it should be picked up by the query. is this possible?
mm10
Contributor
6395 Points
1182 Posts
Re: how to use custom values in gridview query?
Apr 10, 2012 12:22 PM|LINK
Yes, you could use a ControlParameter for this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT s.fname, s.lname, s.rollno
FROM Students WHERE s.rollno=@RollNo
">
<SelectParameters>
<asp:ControlParameter Name="RollNo" ControlID="txt" PropertyName="Text" DefaultValue="20" />
</SelectParameters>
</asp:SqlDataSource>
<asp:TextBox ID="txt" runat="server" />
tdmca
Contributor
2396 Points
661 Posts
Re: how to use custom values in gridview query?
Apr 10, 2012 12:24 PM|LINK
<asp:SqlDataSource ID="sdsMMSPts" runat="server" ConnectionString="<%$ ConnectionStrings:mmsptsConnectionString %>" SelectCommand="SELECT [Recommended], [PatientId] FROM [Patients] WHERE ([PatientId] = @PatientId)"> <SelectParameters> <asp:ControlParameter ControlID="txtAcctNo" Name="PatientId" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource>evello880
Member
226 Points
75 Posts
Re: how to use custom values in gridview query?
Apr 10, 2012 01:24 PM|LINK
http://www.ezzylearning.com/tutorial.aspx?tid=2397431