protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getControls();
}
}
public void getControls()
{
string connn = ConfigurationManager.ConnectionStrings["RiskRegisterDBConnectionString"].ConnectionString;
DataTable ds = DB.GetDataTable("Select * from ControlTable", connn);
// GridView11.DataSource = ds;
GridView11.DataBind();
}
I have tried using AutoGenerationColumn
as "true" and "false" both, but I'm not getting the gridview to display in browser while running the program.
<asp:GridView ID="GridView11" runat="server"
AutogenerateColumns="False" Cellpadding="4"
CssClass="auto-style6" DataKeyNames="Control_ID"
DataSourceID="SqlDataSource1"
Forecolor="#333333" Gridlines="None" Width="1124px" >
CodePudding user response:
Try you code say like this:
public void getControls()
{
string strCon =
ConfigurationManager.ConnectionStrings["RiskRegisterDBConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strCon))
{
string strSQL =
@"SELECT * FROM ControlTable";
using (SqlCommand cmd = new SqlCommand(strSQL, conn))
{
DataTable dt = new DataTable();
conn.Open();
dt.Load(cmd.ExecuteReader());
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}