0

我在我的 asp.net 页面中有一个树视图,当我取消选择单个子节点并选择其他节点时,始终未选择父节点。如果我取消选择了另一个子节点并再次选择它,那么父节点也会选择。我不知道为什么会出现这个问题?==================================================== =================================

    public partial class frmTabMenuManagement : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindMenu();
        }    
    }
    public void BindMenu()
    {
        AdminMenuLogic al = new AdminMenuLogic();
        al.Description = "";
        ddlParentMenu.DataSource = al.FilterAdminMenu();

        ddlParentMenu.DataTextField = "Description";
        ddlParentMenu.DataValueField = "Id";
        ddlParentMenu.DataBind();
        ddlParentMenu.Items.Insert(0, new ListItem("As Parent", "0"));
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        AdminMenuLogic amt = new AdminMenuLogic();

        if (btnSubmit.Text == "Submit")
        {
            if (txtMenuLink.Text == "")
            {
                Response.Write("<script language='javascript'>alert(' Menu Description Cannot be left Empty');</script>");
            }
            else if (txtDestinationLink.Text == "")
            {
                Response.Write("<script language='javascript'>alert(' Destination Link Cannot be left Empty');</script>");

            }
            else
            {
                amt.Description = txtMenuLink.Text;
                amt.IsActive = Convert.ToString(ddlIsActive.SelectedItem);
                amt.Url = txtDestinationLink.Text;
                amt.Parent = Convert.ToInt32(ddlParentMenu.SelectedValue);
                amt.saveAdminMenu();
                Response.Write("<script language='javascript'>alert('" + amt.OutPut + "');</script>");
                txtMenuLink.Text = "";
                txtDestinationLink.Text = "";
                BindMenu();//reflect instant changes
            }
        }
        else if (btnSubmit.Text == "Update")
        {
            amt.id = Convert.ToInt32(gvSearch.SelectedRow.Cells[1].Text);
            amt.Description = txtMenuLink.Text;
            amt.IsActive = Convert.ToString(ddlIsActive.SelectedItem);
            amt.Url = txtDestinationLink.Text;
            amt.Parent = Convert.ToInt32(ddlParentMenu.SelectedValue);
            amt.UpdateAdminMenu();
            Response.Write("<script language='javascript'>alert('" + amt.OutPut + "');</script>");
            txtMenuLink.Text = "";
            txtDestinationLink.Text = "";
            bindGrid();
            btnSubmit.Text = "Submit";
            BindMenu();//reflect instant changes
        }
    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (btnSubmit.Text == "Update")
        {
            btnSubmit.Text = "Submit";
            txtMenuLink.Text = "";
            txtDestinationLink.Text = "";
        }
        bindGrid();


    }

    protected void gvSearch_SelectedIndexChanged(object sender, EventArgs e)
    {

        TabContainer1.ActiveTabIndex = 0;
        ddlParentMenu.Items.Add(gvSearch.SelectedRow.Cells[3].Text);
        ddlParentMenu.SelectedValue = gvSearch.SelectedRow.Cells[3].Text;
        txtMenuLink.Text = Regex.Replace(gvSearch.SelectedRow.Cells[2].Text, "amp;", "");
        txtDestinationLink.Text = Regex.Replace(gvSearch.SelectedRow.Cells[4].Text, "amp;", "");
        ddlIsActive.SelectedValue = gvSearch.SelectedRow.Cells[5].Text;
        btnSubmit.Text = "Update";
    }

    protected void txtMenuLink_TextChanged(object sender, EventArgs e)
    {
        if (char.IsWhiteSpace(txtMenuLink.Text.First()))
        {
            txtMenuLink.Text = Regex.Replace(txtMenuLink.Text, " ", "");
        }
    }

    protected void txtDestinationLink_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (char.IsWhiteSpace(txtDestinationLink.Text.First()))
                {
                    txtDestinationLink.Text = Regex.Replace(txtDestinationLink.Text, " ", "");
                }
            }
            catch (Exception ex)
            {
            }

    }

    protected void ddlParentMenu_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void gvSearch_RowDataBound(Object sender, GridViewRowEventArgs e)
    {

        GridViewRow row = e.Row;
        if (row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[1].Visible = false;
            // e.Row.Cells[3].Visible = false;
        }
        if (row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[1].Visible = false;
            // e.Row.Cells[3].Visible = false;

        }



    }
    protected void gvSearch_PageIndexChanging(Object sender, GridViewPageEventArgs e)
    {
        gvSearch.PageIndex = e.NewPageIndex;
        bindGrid();
    }
    protected void gvSearch_PageIndexChanged(Object sender, EventArgs e)
    {

    }

    void bindGrid()
    {
        AdminMenuLogic al = new AdminMenuLogic();
        al.Description = txtSearch.Text;
        gvSearch.DataSource = al.FilterAdminMenu();
        gvSearch.DataBind();
    }

    protected void ddlIsActive_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
4

0 回答 0