Change ASP.Net GridView Caption Text using jQuery

Last Reply 11 months ago By dharmendr

Posted 11 months ago

How can I change the text of the caption property of a gridview with jquery.

thanks for your reply.

Posted 11 months ago

Hi jmontano,

Check this example. Now please take its reference and correct your code.


<script type="text/javascript" src=""></script>
<script type="text/javascript">
    $(function () {
        $('[id*=btnCaption]').on('click', function () {
            $('[id*=GridView1] caption').html("<b>" + $('[id*=txtCaption]').val() + "</b>");
            return false;
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Caption="<b>Customers</b>">
        <asp:BoundField DataField="Id" HeaderText="Id" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Country" HeaderText="Country" />
<br />
<asp:TextBox ID="txtCaption" runat="server" />
<asp:Button ID="btnCaption" Text="Change Caption" runat="server" />



protected void Page_Load(object sender, EventArgs e)
    if (!this.IsPostBack)
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[3] { 
                        new System.Data.DataColumn("Id", typeof(int)),
                        new System.Data.DataColumn("Name", typeof(string)),
                        new System.Data.DataColumn("Country",typeof(string)) });
        dt.Rows.Add(1, "John Hammond", "United States");
        dt.Rows.Add(2, "Mudassar Khan", "India");
        dt.Rows.Add(3, "Suzanne Mathews", "France");
        dt.Rows.Add(4, "Robert Schidner", "Russia");
        GridView1.DataSource = dt;


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim dt As System.Data.DataTable = New System.Data.DataTable()
        dt.Columns.AddRange(New System.Data.DataColumn(2) {
                            New System.Data.DataColumn("Id", GetType(Integer)),
                            New System.Data.DataColumn("Name", GetType(String)),
                            New System.Data.DataColumn("Country", GetType(String))})
        dt.Rows.Add(1, "John Hammond", "United States")
        dt.Rows.Add(2, "Mudassar Khan", "India")
        dt.Rows.Add(3, "Suzanne Mathews", "France")
        dt.Rows.Add(4, "Robert Schidner", "Russia")
        GridView1.DataSource = dt
    End If
End Sub