0

我已经搜索过,但没有运气...

我在手风琴控件中有一个文本框,它位于数据列表中...我想允许手风琴表单提交一些值,但我无法将这些值从文本框中取出,并且 findcontrol 不起作用。

<asp:DataList ID="AddProjectDataList" runat="server">
<ItemTemplate>

 <asp:HiddenField ID="clientid" runat="server" Value='<%# Eval("mmmclientlistid") %>'></asp:HiddenField>
  <asp:Table ID="ProjectTableClass" runat="server" style="width:600px;height:600px"><asp:TableRow><asp:TableCell VerticalAlign="Top">
<b>New <asp:Label ID="ProjectTypeLabel" Text='<%# Eval("ProjectTypeName") %>' runat="server"></asp:Label> Project</b>
      <table class="AddProject" cellpadding="5">
          <tr>
              <td valign="top">
                  <b>Campaign</b> information:
              </td>
              <td>


                  <asp:DropDownList ID="DDCampaignList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="OnChange_selectCampaign" AppendDataBoundItems="True" >
                      <asp:ListItem Text="SELECT A CAMPAIGN:" Value="-1"></asp:ListItem>
                  </asp:DropDownList>
                  <br />



                  <ajaxToolkit:Accordion
ID="CampaignAccordion"
runat="Server"
SelectedIndex="1"
HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected"
ContentCssClass="accordionContent"
AutoSize="None"
FadeTransitions="true"
TransitionDuration="250"
FramesPerSecond="40"
RequireOpenedPane="false"
SuppressHeaderPostbacks="true">
<Panes>
    <ajaxToolkit:AccordionPane ID="AccordionPane1" runat="server"
        HeaderCssClass="accordionHeader"
        HeaderSelectedCssClass="accordionHeaderSelected"
        ContentCssClass="accordionContent">
        <Header> 
            <asp:LinkButton ID="AddCampaignLink" runat="server">Or Click to Add New Campaign</asp:LinkButton> </Header>
        <Content> 
                             <asp:TextBox ID="campaignNameTextBox" Style="width: 400px" runat="server"></asp:TextBox><br />
                  Description (optional):<br />
                  <asp:TextBox ID="campaignDescriptionTextBox" runat="server" TextMode="MultiLine"
                      Columns="30" Rows="3"></asp:TextBox>
            <br />
            <asp:Button ID="AddCampaignButton" runat="server" Text="Add New Campaign" OnClick="AddCampaign_Click" />
        </Content>
    </ajaxToolkit:AccordionPane>        
</Panes>            
<HeaderTemplate>...</HeaderTemplate>
<ContentTemplate>...</ContentTemplate>

然后在代码隐藏中

protected void AddCampaign_Click(object sender, EventArgs e)
    {
        //click to add campaign
        //campaignname
        //clientid



            HiddenField EID = (HiddenField)FindControl("HiddenFieldEID");
            TextBox campaignNameTextBox = (TextBox)AddProjectDataList.Items[0].FindControl("campaignNameTextBox");
            TextBox campaignDescriptionTextBox = (TextBox)AddProjectDataList.Items[0].FindControl("campaignDescriptionTextBox");

            tbl_campaign newcampaign = new tbl_campaign();
            newcampaign.clientID = Convert.ToInt32(DDClientList.SelectedValue); 
            newcampaign.employeeID = Convert.ToInt32(HiddenFieldEID.Value);
            newcampaign.campaignName = campaignNameTextBox.Text;
            newcampaign.campaignDescription = campaignDescriptionTextBox.Text;


            db.AddTotbl_campaign(newcampaign);

            db.SaveChanges();
    }

如果我摆脱手风琴窗格,它工作正常。控件定位没问题。但是对于手风琴,就没有这样的运气了。(“hiddenFieldEID”字段的位置很好,因为它位于手风琴之外。)

DataList 控件中是否需要单独的 onItemDataBound 事件?如果是这样,里面有什么,我如何将它与 buttonclick 事件联系起来?

谢谢!

4

1 回答 1

1

好吧,我可能刚刚想通了。

我这样做了:

                Control CampaignAccordion = (Control)AddProjectDataList.Items[0].FindControl("CampaignAccordion");
            TextBox campaignNameTextBox = (TextBox)CampaignAccordion.FindControl("campaignNameTextBox");
            TextBox campaignDescriptionTextBox = (TextBox)CampaignAccordion.FindControl("campaignDescriptionTextBox");

它奏效了。没有单独的数据绑定事件。这是正常的做法吗?

于 2012-11-13T19:22:28.813 回答