Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
{      
    Label5.Text =(string)Session["Role_Name"];            
    
    populateGridview();  
}

public void populateGridview()
{
    string qry = "select Pages,[Add],[View],Edit,[Delete] from Role1 where Role_Name= '"+Label5.Text+"'";
    DataSet ds = dut.GetDataSet(qry);
    GridView1.DataSource = ds;
    GridView1.DataBind();
}

Hi everyone,
In this code above inside the populateGridview function The Label5.Text Value I am getting "". Please help how will i use this session value in the query.


[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v2
Comments
Sanket Saxena 14-Apr-14 1:50am    
Follow Tadit solution it will work....But as a suggestion try to remove inline query.

1 solution

C#
if(Session["Role_Name"] != null && !string.IsNullOrEmpty(Session["Role_Name"].ToString()))
{
    string qry = "select Pages,[Add],[View],Edit,[Delete] from Role1 where Role_Name= '" + Session["Role_Name"].ToString() + "'";

    DataSet ds = dut.GetDataSet(qry);
    GridView1.DataSource = ds;
    GridView1.DataBind();
}
 
Share this answer
 
Comments
Aarti Meswania 14-Apr-14 1:46am    
5+! :)
Thanks a lot Aarti. :)
Aarti Meswania 14-Apr-14 2:40am    
welcome! :)
Member 10578683 14-Apr-14 2:01am    
i did like this.now it is coming. but when i checked my checkboes only N is updating in my database.
protected void Button7_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
if (Session["Role_Name"] != null && !string.IsNullOrEmpty(Session["Role_Name"].ToString()))
{
CheckBox chkAdd = (row.Cells[1].FindControl("CheckBox1") as CheckBox);
CheckBox chkEdit = (row.Cells[2].FindControl("CheckBox2") as CheckBox);
CheckBox chkView = (row.Cells[3].FindControl("CheckBox3") as CheckBox);
CheckBox chkDelete = (row.Cells[4].FindControl("CheckBox4") as CheckBox);
// string strID = row.Cells[0].Text;
string Pages = row.Cells[0].Text;
con.Open();
string query = "Update Role1 set [Add]='" + (chkAdd.Checked == true ? 'Y' : 'N') + "', [View]='" + (chkView.Checked == true ? 'y' : 'N') + "' ,[Edit]='" + (chkEdit.Checked == true ? 'y' : 'N') + "' ,[Delete]='" + (chkDelete.Checked == true ? 'y' : 'N') + "' where Pages ='" + Pages + "' and Role_Name='" + Session["Role_Name"].ToString() + "'";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
populateGridview();

con.Close();
}
}
}
}
Debug and see what is the dynamic query formed. See if it is correct or not. You can take that and run directly in SSMS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900