1. 程式人生 > 實用技巧 >.NET ------ 樹形選單,點選單選按鈕觸發相應事件

.NET ------ 樹形選單,點選單選按鈕觸發相應事件

主要就是包括兩個,樹形選單和單選按鈕

先獲取選單的所有值,在實現點選獲取相應資料

    <table width ="100%" cellpadding="0" cellspacing="0" border="0" class="ttable_border_none">
           <tr><td align ="left"><asp:HiddenField ID="HidTreeWhere" runat="server" Value=""/><img src="../../qdAdmin/qdimages/files/check01/00.png" />採購單</td></tr>
    <asp:Repeater ID ="RepeaterTree" runat="server" OnItemDataBound="RepeaterTree_ItemDataBound">
    <ItemTemplate>
           <tr  bgcolor ="#FFFFFF" onMouseOver="this.bgColor='#EEEEEE'" onMouseOut="this.bgColor='#FFFFFF'">
              <td align ="left" style="white-space: nowrap">
               <asp:HiddenField ID="HidGuid" runat="server" Value='<%# DataBinder.Eval(Container.DataItem,"CaiGouDanGuid") %>' /><img src="../../qdAdmin/qdimages/files/check01/10.png" />
               <asp:CheckBox ID="chkMark" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"CaiGouDanMark") %>' AutoPostBack="true" OnCheckedChanged="chkMark_CheckedChanged" />
                   <a href="javascript:return false;" title="詳細"  onclick="javascript:WebDialogLoad('<%# DataBinder.Eval(Container.DataItem,"CaiGouDanMark") %>',1000,600, 'CaiGou_List_win.aspx?pwidth=980&pheight=480&id=<%# DataBinder.Eval(Container.DataItem,"CaiGouDanGuid") %>&edit=show')" ><img src="../../qdadmin/qdimages/Select.png" border="0" title="詳細"></a>
             </td>
           </tr>

    </ItemTemplate>
    </asp:Repeater>
    </table> 

獲取相應值,藉助Repeater 進行遍歷,前面和 <%# DataBinder.Eval(Container.DataItem,"資料庫欄位名") %> 一塊連用

    private void TreeLoad()
    {
        #region Tree
        List<ITEM.Model.Mis4.BCaiGouDan> mTreeList = _bllCaiGouDan.GetListSelBCaiGouDan3("CaiGouDanMark,CaiGouDanGuid", base.EnterpriseGuid, GetSearchSql_Tree() + "
and DeptCode like '"+_XUserLogin.UserLoginOrganizationCode+"%' order by CaiGouDanMark"); this.RepeaterTree.DataSource = mTreeList; this.RepeaterTree.DataBind(); #endregion } protected void RepeaterTree_ItemDataBound(object sender, RepeaterItemEventArgs e) {
string s = HidTreeWhere.Value; if (s == string.Empty) return; CheckBox chk = (CheckBox)e.Item.FindControl("chkMark"); HiddenField hid = (HiddenField)e.Item.FindControl("HidGuid"); if (s.IndexOf(hid.Value) >= 0) { chk.Checked = true; } else { chk.Checked = false; } }

點選單選獲取相應的值

 protected void chkMark_CheckedChanged(object sender, EventArgs e)
    {
        HidTreeWhere.Value = string.Empty;
        string s = string.Empty;
        for (int i = 0; i <= RepeaterTree.Items.Count - 1; i++)
        {
            CheckBox chk = (CheckBox)RepeaterTree.Items[i].FindControl("chkMark");
            HiddenField hid = (HiddenField)RepeaterTree.Items[i].FindControl("HidGuid");
            if (chk.Checked == true)
            {
                string sign = s == string.Empty ? "" : ",";
                s += sign + hid.Value;
            }
        }
        s = "'" + s + "'";
        s = s.Replace(",", "','");
        HidTreeWhere.Value = s;

        HtmlTableLoad();
    }