JOYSON says:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
if (!this.IsPostBack)
{
this.BindDetailsView();
}
}
private void BindDetailsView()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT pan, bankname, branch_code, bank_address, account_type, account_no, ifsc_code FROM tblmadmin"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
}
}
}
}
}
Please replace the above code with the below.
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
else
{
if (!this.IsPostBack)
{
this.BindDetailsView(Page.User.Identity.Name);
}
}
}
private void BindDetailsView(string userName)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT pan, bankname, branch_code, bank_address, account_type, account_no, ifsc_code FROM tblmadmin WHERE UserName = " + userName))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
DetailsView1.DataSource = dt;
DetailsView1.DataBind();
}
}
}
}
}