locked
Search Option RRS feed

  • Question

  • User-1499457942 posted

    Hi

     I have below code. Search option does not work . Secondly i want to add my own headings

    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContentPlaceHolder" runat="server">
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function () {
                $("#gvw1").prepend($("<thead></thead>").append($(this).find("tr:first"))).dataTable();
            });
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
                        <div class="table-responsive">
    <asp:GridView ID="gvw1" OnPreRender="GridView1_PreRender" runat="server"
    CssClass="table table-bordered table-striped "
    ClientIDMode="Static" ></asp:GridView>
    </div> </asp:Content> public partial class ViewBfb : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetData(); } } void GetData() { using (SqlConnection con = new SqlConnection(CommonFunction.connectionString)) { SqlCommand cmd = new SqlCommand("Select * from [Data]", con); cmd.CommandType = CommandType.Text; con.Open(); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); if (dt.Rows.Count > 0) { gvw1.DataSource = dt; gvw1.DataBind(); } dt.Clear(); } }

    Thanks

    Thursday, August 9, 2018 4:07 PM

All replies

  • User-893317190 posted

    Hi JagjitSingh,

    What headings do you want? You could change head through asp:BoundField’s property HeaderText ,jquery or through gridview’s headerow property.

    Below is my code.

     <form id="form1" runat="server">
             <div class="table-responsive">
                        <asp:GridView ID="gvw1"  runat="server"
                                            CssClass="table table-bordered table-striped "
                                            ClientIDMode="Static" >
    
                            <Columns>
                                <asp:BoundField DataField="CustomerId" HeaderText="myCustomizedCustomerId" />
                                
                            </Columns>
                            
                        </asp:GridView></div>
        </form>
    </body>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function () {
                // change the sixth column's header
                $("#gvw1 tr:eq(0) th:eq(5)").replaceWith("<th >myHeadThroughJquery</th>")
                $("#gvw1").prepend($("<thead></thead>").append($(this).find("tr:first"))).dataTable();
            });
        </script>
    

    Code behind.

    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    GetData();
                    gvw1.HeaderRow.Cells[3].Text = "myHeaderThroughtHeaderRow";
                  
                }
            }
    
            void GetData()
            {
                using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("Select * from [customers]", con);
                    cmd.CommandType = CommandType.Text;
                    con.Open();
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        gvw1.DataSource = dt;
                        gvw1.DataBind();
                    }
                    dt.Clear();
                }
    
            }
    

    The result.

    As to search option , I have used code above , but it’s search option works well . Could you please post more code that may cause the problem so that we could reproduce your problem?
     

    Best regards ,

    Ackerly Xu

    Friday, August 10, 2018 9:05 AM