i m having a webpage which is having a gridview which is displaying data from database........now on the same same web page their exists some hyperlinks namely A, B ,C.....upto Z ............can anybody plz help me out on how to display the new data (clicking of hyperlink A result in data starting from letter A) in same gridview....
thank u :?

Dani AI

Generated

Short answer: keep the alphabet links above the GridView but run a small, parameterized query for the chosen letter and rebind the GridView — this avoids paging and is efficient for large tables. That follows ’s idea of “pass A and rebind,” and expands on ’s LinkButton suggestion with a production-friendly pattern that avoids filtering huge DataSets in memory.

A compact pattern (markup + handler) is shown here:

<!-- Letter link -->
<asp:LinkButton ID="lnkA" runat="server" CommandArgument="A" OnCommand="Letter_Command">A</asp:LinkButton>

<!-- code-behind (C#) -->
protected void Letter_Command(object sender, CommandEventArgs e)
{
    string letter = e.CommandArgument.ToString();
    var dt = new DataTable();
    using (var conn = new SqlConnection(connString))
    using (var cmd = new SqlCommand("SELECT Col1,Col2 FROM MyTable WHERE MyColumn LIKE @p", conn))
    {
        cmd.Parameters.AddWithValue("@p", letter + "%");
        using (var da = new SqlDataAdapter(cmd)) da.Fill(dt);
    }
    GridView1.DataSource = dt;
    GridView1.DataBind();
}

Practical tips and gotchas: generate the A–Z controls with a Repeater so the markup stays clean; query the DB for available starting letters (SELECT DISTINCT UPPER(LEFT(col,1))...) to disable letters with no results; use parameterized SQL (or EF/LINQ with a StartsWith) so the database can use indexes — avoid leading wildcards. Use an UpdatePanel or AJAX call to refresh only the GridView to prevent a full page postback. Watch collation/case-sensitivity and prefer setting the parameter value to letter + "%", or supply the proper SqlDbType instead of AddWithValue for predictable types.

Common troubleshooting: remember GridView.DataBind() after setting the data source; preserve the selected letter across postbacks via QueryString or ViewState if needed; for small tables caching a full DataTable and client-side filtering is fine, but for larger tables prefer DB-side filtering to keep response times low.

Recommended Answers

All 6 Replies

i had already gone through these link...actually i dont want it as paging.....

then wot exactly u want..?

my links r above the gridview ..............

i believe than it would be more easy to control the grid by simply passing A, B, C
on linkbuttnclick event.. pass it to query and rebind the gridview...!

Hello deeptakshd,
If it is related to filtering only then try something like this,

1) Replace your hyperlink with linkbutton
2) Add code similar to below in your linkbutton click event. Suppose if it filter value with A then,

'Get Dataset for binding in gridview.
'Dim ds as DataSet = YourFunctionThatReturnsDataset()

Dim dv As New DataView()
With dv
	.Table = ds.Tables(0)
	.RowFilter = "dataColumnName='A%'"
End With
yourGridView.DataSource = dv
yourGridView.DataBind()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.