if (e.CommandName == "ImageButton2_Click") { int rowindex = Convert.ToInt32(e.CommandArgument); //Get Row GridViewRow gvr = GridView2.Rows[rowindex]; { Label ID = (Label)GridView2.Rows[rowindex].Cells[1].FindControl("Role_ID"); string Role_ID = ID.Text; con.Open(); using (SqlCommand comm = new SqlCommand("select [UserName] from Login where Role_ID =@Role", con)) { // 2. define parameters used in command object SqlParameter para = null; para = new SqlParameter(); para.ParameterName = "@Role"; para.Value = Role_ID; comm.Parameters.Add(para); SqlDataReader reade = comm.ExecuteReader(); ImageButton button = (ImageButton)GridView2.Rows[rowindex].Cells[5].FindControl("ImageButton2"); button.Visible = false; ArrayList yourList = new ArrayList(); if (reade.HasRows) { if (reade != null) { while (reade.Read()) { //ImageButton button =(ImageButton)GridView2.Rows[rowindex].Cells[5].FindControl("ImageButton2"); button.Visible = true; yourList.Add(Convert.ToString(reade[0])); Session["UserName"] = yourList[0]; } } } } if (Session["UserName"].ToString() == null) { ImageButton button = (ImageButton)GridView2.Rows[rowindex].Cells[5].FindControl("ImageButton2"); button.Visible = false; } else { ImageButton button = (ImageButton)GridView2.Rows[rowindex].Cells[5].FindControl("ImageButton2"); button.Visible = true; ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["UserName"].ToString() + "');", true); con.Close(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)