Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:35:38+00:00 2026-06-18T15:35:38+00:00

I have a gridView in asp, currently using the following datasource – <asp:SqlDataSource ID=SqlDataSourceTEST

  • 0

I have a gridView in asp, currently using the following datasource –

<asp:SqlDataSource ID="SqlDataSourceTEST" runat="server" 
    ConnectionString="connection string" 
    SelectCommand="SELECT * FROM table">
</asp:SqlDataSource>

I can adjust the SelectCommand in the code behind by doing –

SqlDataSourceTEST.SelectCommand = "SELECT * FROM table WHERE ID =" + iD;

However I am now adjusting the code to populate the gridView through a web service method –

[WebMethod]

    public DataSet sMethod()
    {
        using (SqlConnection cnn = new SqlConnection(DBcon))
        {

            string sql = "SELECT * FROM table";
            SqlDataAdapter da = new SqlDataAdapter(sql, cnn);
            DataSet ds = new DataSet();
            da.Fill(ds, "table");

            return ds;

        }
    }

Then on page load populating the gridView –

WebService1 ws = new WebService1();
gridView1.DataSource = ws.sMethod();
gridView1.DataBind();

Is there a way I can adjust the string sql part of the web method in the code behind to add variables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:35:39+00:00Added an answer on June 18, 2026 at 3:35 pm

    Make your WebMethod accept parameter:

    public DataSet sMethod(string sql)
    {
       if (string.IsNullOrEmpty(sql))
       {
           sql = "SELECT * FROM table";
       } 
       SqlDataAdapter da = new SqlDataAdapter(sql, cnn);
    
       ...
    }
    

    and call it from website:

    string sql = "SELECT * FROM table WHERE ID =" + iD;
    WebService1 ws = new WebService1();
    gridView1.DataSource = ws.sMethod(sql);
    gridView1.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, currently, within an asp gridview, I have the following <span id=btnEdit runat=server onclick=ShowEditCriteriaFilterDialog('<%#Eval(intSMCID)%>',
I have an ASP.NET GridView which is populated from a SQL Server database. This
im using asp.net with c#. I have a gridview and there is a TemplateField
I am using VS2005 C#. Currently I have a GridView, and I have changed
I am using VS2005. Currently I have a delete linkButton in my gridview, and
I'm currently using an SqlDataSource in ASP.NET/C# to let users insert, delete and update
Here is my ASP code: <asp:GridView ID=WagerTable runat=server AutoGenerateColumns=False CssClass=basix > <columns> <asp:BoundField DataField=GameName
I currently have a gridview that has an asp:ButtonField as one of the columns.
I have a page that houses an asp GridView and I would like to
I am currently developing an ASP.net c# application. I have a grid view which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.