1. 程式人生 > >如何獲取datalist裡面子控制元件(如:dropdownlist)的值[WEB學習示例]

如何獲取datalist裡面子控制元件(如:dropdownlist)的值[WEB學習示例]

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)//資訊顯示編輯與刪除
    {
        pages = Request["page"];
        LinkButton LBut2 = (LinkButton)DataList1.Items[0].FindControl("LinkButton2");
        LinkButton LBut3 = (LinkButton)DataList1.Items[0].FindControl("LinkButton3");
        if (Session["UserName"] != null)
        {
            if (e.CommandName == "BianJi_getID")
            {
                if (LBut2 != null) { strID = Convert.ToInt16(e.CommandArgument.ToString()).ToString(); }
                if (TextBox9.Text != "") { Session["BaoChi"] = TextBox9.Text; }
                Response.Redirect("Gong_Dan_List.aspx?id=" + strID + "&page=" + pages + "");
            }

            if (e.CommandName == "ShuanChu_getID")
            {
                if (LBut3 != null) { strID = Convert.ToInt16(e.CommandArgument.ToString()).ToString(); }
                ShuanChu_JiLu();
            }
        }
        else
        { Response.Redirect("../default.aspx"); }
    }

CheckBox chk = (CheckBox)DataList1.Items[0].FindControl("CheckBox1");

Control shousuoKJ = (Control)Master.FindControl("ContentPlaceHolder1");
        for (int Bi = 1; Bi <= 3; Bi++)
        { Button Bton = (Button)shousuoKJ.FindControl("Button" + Bi.ToString()); if (Bton != null) { Bton.Enabled = false; } }

LinkButton LBut3 = (LinkButton)Controls.Count[0].FindControl("LinkButton3");

----------------------------------------------------------------------------

<asp:LinkButton ID="LinkButton3" runat="server"
                                                                    CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id")%>'
                                                                    CommandName="GuanLi_getID" Enabled="False" ToolTip="網站管理。">刪除</asp:LinkButton>