protected void Button1_Click(object sender, EventArgs e) { dt.Columns.Add("Name"); DataRow dr = dt.NewRow(); dr[0] = "Jesus"; dt.Rows.Add(dr); BoundField BFiled1 = new BoundField(); BFiled1.HeaderText = "Name"; BFiled1.DataField = "Name"; grd1.Columns.Add(BFiled1); grd1.DataSource = dt; grd1.DataBind(); }
Mark as Answer if its helpful to you Kumaraspcode2009@gmail.com
<asp:TextBox ID="txtCount" runat="server"></asp:TextBox> <asp:Button ID="btnSubmit" runat="server" Text="GetRecords" OnClick="GetRecords" /> <br> <asp:DataGrid ID="datagrid1" runat="server" AllowSorting="true" AutoGenerateColumns="false"> </asp:DataGrid>
protected void GetRecords(object sender,EventArgs e) { datagrid1.PageSize = int.Parse(txtCount.Text.ToString()); DataTable table = new DataTable(); using (SqlConnection con = new SqlConnection(_connStr)) { string sqlquery = "select *from Login"; using (SqlCommand cmd = new SqlCommand(sqlquery, con)) { SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(table); } datagrid1.DataSource = table; datagrid1.DataBind(); } }
Login to post response