Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Gridview delete ,No Delete ,No errors.

$
0
0
<script runat="server">
    SqlConnection objConn = new SqlConnection();
    SqlCommand objCmd = new SqlCommand();
    SqlDataAdapter dtAdapter = new SqlDataAdapter();
    DataTable dt = new DataTable();
    String strConnString, strSQL;

    void Page_Load(object sender,EventArgs e)
    {
        strConnString = "Server=localhost;UID=sa;PASSWORD=12345;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
        if (Convert.ToString(Session["strUser"]) == "")
        {
            Response.Redirect("index.aspx");
            Response.End();
        }
		if(!Page.IsPostBack)
		{
			BindData();
		}
    }


    void BindData()
    {

        strSQL = "SELECT * FROM AddRoom";
        objConn.ConnectionString = strConnString;
        objCmd.Connection = objConn;
        objCmd.CommandText = strSQL;
        objCmd.CommandType = CommandType.Text;
        objConn.Open();

        dtAdapter.SelectCommand = objCmd;
        dtAdapter.Fill(dt);

        myGridView.DataSource = dt;
        myGridView.DataBind();

        dtAdapter = null;
        objConn.Close();
        objConn = null;
    }

    void modDeleteCommand(Object sender, GridViewDeleteEventArgs e)
    {
        Label lblRoomID = (Label)myGridView.Rows[e.RowIndex].FindControl("lblRoomID");
        strSQL = "DELETE FROM AddRoom WHERE RoomID = '" + lblRoomID.Text + "'";
        objCmd.Connection = objConn;
        objCmd.CommandText = strSQL;
        objCmd.CommandType = CommandType.Text; ;
        objCmd.CommandText = strSQL;
        myGridView.EditIndex = -1;
        BindData();


    }

     void myGridView_RowDataBound(Object s, GridViewRowEventArgs e)
	{
        Label lblRoomID = (Label)(e.Row.FindControl("lblRoomID"));
        if (lblRoomID != null)
		{
            lblRoomID.Text = (string)DataBinder.Eval(e.Row.DataItem, "RoomID", "{0}");
		}

        Label lblRoom = (Label)(e.Row.FindControl("lblRoom"));
        if (lblRoom != null)
		{
            lblRoom.Text = (string)DataBinder.Eval(e.Row.DataItem, "RoomName","{0}");
		}
        Label lblSize = (Label)(e.Row.FindControl("lblSize"));
        if (lblSize != null)
        {
            lblSize.Text = (string)DataBinder.Eval(e.Row.DataItem, "Size", "{0}");
        }

        Label lblLocation = (Label)(e.Row.FindControl("lblLocation"));
        if (lblLocation != null)
        {
            lblLocation.Text = (string)DataBinder.Eval(e.Row.DataItem, "Location", "{0}");
        }
        HyperLink hplDetail = (HyperLink)e.Row.FindControl("hplDetail");
        if ((hplDetail != null))
        {
            hplDetail.NavigateUrl = "JavaScript:void(0);";
            hplDetail.Attributes.Add("OnClick", "JavaScript:OpenPopup('popupDetailSchedule.aspx?RoomID=" + e.Row.DataItemIndex.ToString("RoomID").ToString() + "');");
        }
        HyperLink hplEdit = (HyperLink)(e.Row.FindControl("hplEdit"));
        if (hplEdit != null)
        {
            hplEdit.NavigateUrl = "editRoomAdmin.aspx?RoomMeetID=" + (string)DataBinder.Eval(e.Row.DataItem, "RoomMeetID", "{0}");
        }
	}
	void ShowPageCommand(Object s, GridViewPageEventArgs e)
	{
		myGridView.PageIndex = e.NewPageIndex;
		BindData();
	}</script>


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>