如何从面板控制按钮

本文关键字:控制 按钮 | 更新日期: 2023-09-27 18:07:58

我是ASP.NET的新手。我选了一个Panel。在Panel里面,我选了一张桌子。表内有TextBoxRadioButtonButton控件。

我在button_click事件中写了一些代码。但是什么也没发生。button_click事件未触发。现在该怎么办?

我也有一些其他的东西在面板。但是没有点击事件。

代码如下:

<asp:Panel ID="Pnlproducts" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
    <asp:DataList ID="DLProducts" runat="server" RepeatColumns="3" Width="600px" OnSelectedIndexChanged="DLProducts_SelectedIndexChanged">
        <ItemTemplate >
            <table align="left" class="auto-style6" style="border-color:#9900FF;border-left:1px;border-right:1px;border-top:1px;">
            <tr>
                <td style="border-color: #000000; border-width: 1px; border-bottom-style: ridge" class="auto-style8">
                    <asp:Label ID="lblProductName" runat="server" Text="<%# Bind('ProductName') %>" Font-Bold="True"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="auto-style9">
                    <asp:Image ID="Image2" runat="server" Height="160px" ImageUrl="<%# Bind('ProductImage') %>" Width="173px" Style="border:ridge 1px black" />
                </td>
            </tr>
            <tr>
                <td class="auto-style9"><strong>Price:</strong><asp:Label ID="lblPrice" runat="server" Text="<%# Bind('ProductPrice') %>" Font-Bold="True" ForeColor="Red"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="auto-style9">
                    <asp:Button ID="Addtocartbtn" runat="server" BorderStyle="Solid" BorderWidth="1px" OnClick="Addtocartbtn_Click" Text="Add to Cart" Width="170px" BorderColor="Black" />
                </td>
            </tr>
            </table>
        </ItemTemplate>
    </asp:DataList>                     
</asp:Panel>
<asp:Panel ID="Panel111" runat="server" ScrollBars="Auto" Height="500px" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
    <table class="auto-style16">
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
    </table>
</asp:Panel>
</td>
<td>
    <asp:Panel ID="pnlCatagory" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
        <div class="auto-style7">
            <asp:DataList ID="dlCatagory" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
                <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                <ItemTemplate>
                    <asp:LinkButton ID="LBTNCatagoty" runat="server" CommandArgument="<%# Bind('CatagoryID') %>" Font-Bold="True" OnClick="LBTNCatagoty_Click" Text="<%# Bind('CatagoryName') %>"></asp:LinkButton>
                </ItemTemplate>
            </asp:DataList>
        </div>
    </asp:Panel>
                                    <asp:Panel ID="Panel222" runat="server" Height="500px" ScrollBars="Auto" BorderColor="Black" BorderStyle="Inset" BorderWidth="1px">
    <table class="auto-style10">
        <tr>
            <td class="auto-style7" colspan="2"><strong>Please Type Your Details</strong></td>
        </tr>
        <tr>
            <td class="auto-style12"></td>
            <td class="auto-style11"></td>
        </tr>
        <tr>
            <td class="auto-style15">Name :</td>
            <td class="johnykbd8">
               <asp:TextBox ID="TextBoxUserName" runat="server" Width="180px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style15">E-mail :</td>
            <td class="johnykbd8">
                <asp:TextBox ID="TextBoxEmail" runat="server" Width="180px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style15">Address:</td>
            <td class="johnykbd8">
                <asp:TextBox ID="TextBoxAdress" runat="server" Height="90px" TextMode="MultiLine" Width="180px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style15">Gender :</td>
            <td>
                <asp:RadioButton ID="RadioButton1" runat="server" GroupName="GenderGroup" Text="Male" /><br />
          &nbsp;<asp:RadioButton ID="RadioButton2" runat="server" GroupName="GenderGroup" Text="Female" />
            </td>
        </tr>
        <tr>
             <td class="auto-style15">Mobile:</td>
             <td class="johnykbd8">
                 <asp:TextBox ID="TextBoxMobileNum" runat="server" Width="180px"></asp:TextBox>
             </td>
        </tr>
        <tr>
            <td class="auto-style15">Photo :</td>
            <td class="johnykbd8">
                <asp:FileUpload ID="FileUploaduserphoto" runat="server" Width="180px" />
            </td>
        </tr>
        <tr>
            <td class="auto-style15">Payment :</td>
            <td>
                <asp:RadioButton ID="RadioButton3" runat="server" GroupName="Paymentgroup" Text="Visa" /><br />
                <asp:RadioButton ID="RadioButton4" runat="server" GroupName="Paymentgroup" Text="MasterCard" /><br />
                <asp:RadioButton ID="RadioButton5" runat="server" GroupName="Paymentgroup" Text="Cash On Delivery" />
            </td>
        </tr>
        <tr>
            <td class="auto-style15">Review :</td>
            <td>
                <asp:TextBox ID="TextBoxreview" runat="server" Width="180px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style15">Total : </td>
            <td>BDT :<asp:Label ID="Labelshopamount" runat="server"></asp:Label></td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:ImageButton ID="ImageButtonOrderNow" runat="server" ImageUrl="~/Images/Designing/order.jpg" OnClick="ImageButtonOrderNow_Click" Width="250px" />
            </td>
        </tr>
    </table>
</asp:Panel>

如何从面板控制按钮

如果按钮位于数据列表或gridview中,则设置CommandName属性。数据绑定对象(datalist, gridview)有ItemCommand-event。将代码放在这个事件中。伪代码:

if (e.CommandName.equals(your_command_name)){ label1.text = e.CommandArgument };