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 6736193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:06:04+00:00 2026-05-26T11:06:04+00:00

Here is my sql datasource details <asp:SqlDataSource ID=dsMoodleQuiz runat=server ConnectionString=<%$ ConnectionStrings:OnlineMeetingConnectionString %> ProviderName=<%$ ConnectionStrings:OnlineMeetingConnectionString.ProviderName

  • 0

Here is my sql datasource details

  <asp:SqlDataSource ID="dsMoodleQuiz" runat="server" 
    ConnectionString="<%$ ConnectionStrings:OnlineMeetingConnectionString %>" 
    ProviderName="<%$ ConnectionStrings:OnlineMeetingConnectionString.ProviderName %>" 

    SelectCommand="SELECT Name, UserID, Grade, FirstName, LastName, Email, TimeModified, IDNumber FROM tbMoodleQuiz WHERE (FirstName = @FirstName) AND (LastName = @LastName)" 
    onselecting="dsMoodleQuiz_Selecting">
    <SelectParameters>
        <asp:Parameter Name="FirstName" />
        <asp:Parameter Name="LastName" />
    </SelectParameters>
</asp:SqlDataSource>

A gridview by name gvDetails is attached to dsMoodleQuiz . On button click I would like

gridview to get populated.

Here is the code on button click

 protected void btnSearch_Click(object sender, EventArgs e)
 {
    dsMoodleQuiz.SelectParameters.Add("@FirstName", System.Data.DbType.String, "Jhon");
    dsMoodleQuiz.SelectParameters.Add("@LastName", System.Data.DbType.String, "Wald");

    GridView1.DataBind();
}

Why is this not working …?? Am I missing any code …?? Appreciate the help

  • 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-05-26T11:06:04+00:00Added an answer on May 26, 2026 at 11:06 am

    This is sample example on how to search grid view and populating results on that search criteria using sqldatasource…..

    grid view binding …..

         <asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
    AllowSorting="true" DataSourceID="dsGridview" Width="540px" PageSize="10">
    <Columns>
        <asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" />
        <asp:TemplateField HeaderText="First Name" SortExpression="FirstName">
            <ItemStyle Width="120px" HorizontalAlign="Left" />
            <ItemTemplate>
                <asp:Label ID="lblFirstname" Text='<%# HighlightText(Eval("FirstName")) %>' 
                    runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Last Name" SortExpression="LastName">
            <ItemStyle Width="120px" HorizontalAlign="Left" />
            <ItemTemplate>
                <asp:Label ID="lblLastname" Text='<%# HighlightText(Eval("LastName")) %>' 
                runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Department" HeaderText="Department" 
            SortExpression="Department" ItemStyle-Width="130px" />
        <asp:BoundField DataField="Location" HeaderText="Location" 
            SortExpression="Location" ItemStyle-Width="130px" />
    </Columns>
    </asp:GridView>
    

    and sql datasource is like this …

       <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM People"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        FilterExpression="firstname like '%{0}%' or lastname like '%{1}%'">
        <FilterParameters>
            <asp:ControlParameter Name="firstname" ControlID="txtSearch" PropertyName="Text" />
            <asp:ControlParameter Name="lastname" ControlID="txtSearch" PropertyName="Text" />
        </FilterParameters>
      </asp:SqlDataSource>
    

    adding text box for searching ..

        <asp:TextBox ID="txtSearch" runat="server" />
    <asp:ImageButton ID="btnSearch" ImageUrl="images/searchbutton.png" runat="server" />
    <asp:ImageButton ID="btnClear" ImageUrl="images/clearbutton.png" runat="server" />
    

    and this is code for binding and entering text into text box

        using System.Text.RegularExpressions;
    Partial;
    class GridviewwithHighlightedSearch : System.Web.UI.Page {
    
        //  Create a String to store our search results
        private string SearchString = "";
    
        string HighlightText(string InputTxt) {
            //  This function is called whenever text is displayed in the FirstName and LastName 
            //  fields from our database. If we're not searching then just return the original 
            //  input, this speeds things up a bit
            if ((SearchString == "")) {
                return InputTxt;
            }
            else {
                //  Otherwise create a new regular expression and evaluate the FirstName and 
                //  LastName fields against our search string.
                Regex ResultStr;
                ResultStr = new Regex(SearchString.Replace(" ", "|"), RegexOptions.IgnoreCase);
                return ResultStr.Replace(InputTxt, new MatchEvaluator(new System.EventHandler(this.ReplaceWords)));
            }
        }
    
        public string ReplaceWords(Match m) {
            //  This match evaluator returns the found string and adds it a CSS class I defined 
            //  as 'highlight'
            return ("<span class=highlight>" 
                        + (m.ToString + "</span>"));
        }
    
        protected void btnClear_Click(object sender, System.Web.UI.ImageClickEventArgs e) {
            //  Simple clean up text to return the Gridview to it's default state
            txtSearch.Text = "";
            SearchString = "";
            Gridview1.DataBind();
        }
    
        protected void btnSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e) {
            //  Set the value of the SearchString so it gets 
            SearchString = txtSearch.Text;
        }
    }
    

    and this is the css style for hilighting..

    and this is teh image for the above grid view

        <style type="text/css">
       .highlight {text-decoration: none;color:black;background:yellow;}
    </style>
    

    i hope it will helps you…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my ASP code: <asp:GridView ID=WagerTable runat=server AutoGenerateColumns=False CssClass=basix > <columns> <asp:BoundField DataField=GameName
I am new to SQL Server 2008 fill factor, as mentioned here in SQL
Here is my SQL Statement which is not returning DISTINCT Thread Titles. SELECT DISTINCT
Have other people here played with SQL Server 2008 Compression at either the page
Here's my current SQL statement: SEARCH_ALBUMS_SQL = SELECT * FROM albums WHERE title LIKE
Here is the scenario: SQL Server 2000 (8.0.2055) Table currently has 478 million rows
Here is the scenario: IIS 6 and SQL Server 2005 on same machine: I
Here , it is said that Sql Server Compact allows up to 256 connections.
ok the following is the code for the gridview: <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False BorderColor=#3399FF
Here is my Resource element in context.xml :: <Resource name=jdbc/myoracle auth=Container type=javax.sql.DataSource driverClassName=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@localhost:1521:XE

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.