更改为edite模式时,在gridview中保存复选框状态

时间:2016-07-05 18:47:36

标签: c# asp.net

当我点击gridview中的图像按钮时,某些单元格变得可编辑 但是,它会丢失gridview中的所有复选框值。

有没有办法保存这些值?

我创建了一个函数,它从我的xml中获取复选框值,但是当我在命令时代内调用该函数时,它无效。

当我在gridview中的其他imagebutton命令时代调用该函数时,它不会使某些单元格可编辑,这样就可以运行,并且函数会运行,并且复选框上会显示xml中的值。

由于

    protected void GridView1_SelectedIndexChanged(object sender, GridViewCommandEventArgs e)
{
    showWhoIsPublish();

    ImageButton i = (ImageButton)e.CommandSource;
    // אנו מושכים את האי די של הפריט באמצעות מאפיין לא שמור במערכת שהוספנו באופן ידני לכפתור-תמונה
    string theId = i.Attributes["theItemId"];
    Session["theId"] = theId;

    XmlDocument xmlDoc = XmlDataSource1.GetXmlDocument();

    switch (e.CommandName)
    {
        //אם נלחץ על כפתור מחיקה יקרא לפונקציה של מחיקה
        case "deleteRow":
            popOfDelete.Visible = true;
            string deleteId = (string)Session["theId"];

            string theGameNameDelete = Server.UrlDecode(xmlDoc.SelectSingleNode("//game[@id='" + (string)Session["theId"] + "']/gameName").InnerXml);
            nameOfGameDelete.Text = "'" + theGameNameDelete + "' " + "?";
            showWhoIsPublish();
            break;

        case "editQ":
            string editId = (string)Session["theId"];
            string theGameNameEdit = xmlDoc.SelectSingleNode("//game[@id='" + (string)Session["theId"] + "']/gameName").InnerXml;
            Session["nameOfEdit"] = theGameNameEdit;
            Response.Redirect("Default3.aspx");
            break;

        case "edit":
            addNameTB.Text = "jg";
            showWhoIsPublish();
            break;

        case "cancel":
            GridView1.DataBind();
            showWhoIsPublish();
            break;

        case "approve":

            GridViewRow gvRow = (GridViewRow)(i.Parent.Parent);
            string ApproveId = (string)Session["theId"];
            int index = gvRow.RowIndex;

            string myName = ((TextBox)GridView1.Rows[index].FindControl("nameTB")).Text;
            string myValue = ((DropDownList)GridView1.Rows[index].FindControl("DropDownListT")).Text;
            xmlDoc.SelectSingleNode("//game[@id='" + ApproveId + "']/gameName").InnerText = Server.UrlEncode(myName);
            xmlDoc.SelectSingleNode("//game[@id='" + ApproveId + "']/time").InnerText = Server.UrlEncode(myValue);
            XmlDataSource1.Save();
            // יציאה ממצב של עריכה
            GridView1.EditIndex = -1;
            // ריענון הגריד ויו
            GridView1.DataBind();
            showWhoIsPublish();
            break;


    }
}

 protected void showWhoIsPublish()
{
    //סימון מה שמפורסם
    XmlDocument xmlDoc = XmlDataSource1.GetXmlDocument();
    XmlNodeList myListPublish = xmlDoc.SelectNodes("/games/user[@id='" + Session["id"] + "']/game/@isPublish");

    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        CheckBox chkItem = (CheckBox)GridView1.Rows[i].FindControl("Checkbox1");

        if (myListPublish.Item(i).InnerXml == "yes")
        {
            chkItem.Checked = true;
        }
        else
        {
            chkItem.Checked = false;
        }
    }
}

            

@Html.ValidationSummary(true, "", new { @class = "text-danger" })

0 个答案:

没有答案