Asp.net
asp.net 單選按鈕分組
我目前遇到單選按鈕和分組問題。我在中繼器控制項中有一個 asp 單選按鈕。我將組名屬性設置為“客戶”。頁面載入時,單選按鈕未分組。它不是將 id 欄位設置為組名,而是設置單選按鈕的值欄位。我知道我曾嘗試在中繼器控制項之外設置單選按鈕並且遇到了同樣的問題。這裡發生了什麼?
aspx
<asp:Repeater ID="repCustomers" runat="server"> <HeaderTemplate> <table class="tableDefault" cellpadding="0" cellspacing="0" border="0" style="width: 383px; border: 0px !important"> <tr> <th> </th> <th>Cust. No.</th> <th>Cust. Name</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <asp:RadioButton ID="radCustomer" GroupName="Customer" runat="server" ValidationGroup="Customer" ToolTip='<%#Eval("CustomerNumber") %>' /> </td> <td><%#Eval("CustomerNumber")%></td> <td><%#Eval("Name") %></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>輸出html
<table class="tableDefault" cellpadding="0" cellspacing="0" border="0" style="width: 383px; border: 0px !important"> <tr> <th> </th> <th>Cust. No.</th> <th>Cust. Name</th> </tr> <tr> <td> <span title="111111"><input id="ctl00_PrimaryContent_repCustomers_ctl01_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl01$Customer" value="radCustomer" /></span> </td> <td>111111</td> <td>Jeremy's Test</td> </tr> <tr> <td> <span title="222222"><input id="ctl00_PrimaryContent_repCustomers_ctl02_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl02$Customer" value="radCustomer" /></span> </td> <td>222222</td> <td>My Test</td> </tr> <tr> <td> <span title="333333"><input id="ctl00_PrimaryContent_repCustomers_ctl03_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl03$Customer" value="radCustomer" /></span> </td> <td>333333</td> <td>Jim Bob's BBQ</td> </tr> <tr> <td> <span title="444444"><input id="ctl00_PrimaryContent_repCustomers_ctl04_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl04$Customer" value="radCustomer" /></span> </td> <td>444444</td> <td>New Hope Hamburgers</td> </tr> <tr> <td> <span title="555555"><input id="ctl00_PrimaryContent_repCustomers_ctl05_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl05$Customer" value="radCustomer" /></span> </td> <td>555555</td> <td>Pied Piper Pizza</td> </tr> <tr> <td> <span title="666666"><input id="ctl00_PrimaryContent_repCustomers_ctl06_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl06$Customer" value="radCustomer" /></span> </td> <td>666666</td> <td>Sandy's Subs</td> </tr> <tr> <td> <span title="777777"><input id="ctl00_PrimaryContent_repCustomers_ctl07_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl07$Customer" value="radCustomer" /></span> </td> <td>777777</td> <td>Leonard's Lambchops</td> </tr> <tr> <td> <span title="888888"><input id="ctl00_PrimaryContent_repCustomers_ctl08_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl08$Customer" value="radCustomer" /></span> </td> <td>888888</td> <td>Dave's Diamond Deli</td> </tr> <tr> <td> <span title="999999"><input id="ctl00_PrimaryContent_repCustomers_ctl09_radCustomer" type="radio" name="ctl00$PrimaryContent$repCustomers$ctl09$Customer" value="radCustomer" /></span> </td> <td>999999</td> <td>Ernie's Eatery</td> </tr> </table>
我終於通過創建一個普通的單選按鈕並使用伺服器端 eval 設置值來解決這個問題。
<input type="radio" name="radCustomer" value='<%#Eval("CustomerNumber") %>' />現在,當應用程序執行回發時,我檢查 Request.Form[“radCustomer”] 的值。這完美無缺。