开发者

ASP.NET: checkboxlist with textbox?

开发者 https://www.devze.com 2023-01-30 19:07 出处:网络
I\'m working in ASP.NET and I have a CheckBoxList where I want one of the options to be basically like \"Other: _.\" So I need to include a textbox where the user can fill in their own option. It does

I'm working in ASP.NET and I have a CheckBoxList where I want one of the options to be basically like "Other: _." So I need to include a textbox where the user can fill in their own option. It doesn't seem like there's a way to include a textbox inside of a checkboxlist, however. What's the best way to make this work?

-UPDATE-

If using a separate textbox co开发者_开发百科ntrol, how do I position it so it will align correctly with the checkbox?


Make the textbox a separate control on the page, then in your codebehind, check to see if other is checked. If it is, pull the value of the textbox, and use that.

To answer the question in your edit: You'll have to play with the CSS of the page to get it positioned correctly. How you do it depends on the layout of the page, among other things. I recommend posting some of the HTML from your page in another question and ask about how to position them.


What @Kyle Trauberman said...

Make the textbox a separate control on the page, then in your codebehind, check to see if other is checked. If it is, pull the value of the textbox, and use that.

Plus use javascript to hide or gray out the option unless the checkbox is selected.


string test="";
<asp:CheckBoxList ID="chk_list" runat="server">
<asp:ListItem Value="00">xxxx</asp:ListItem>
</asp:CheckBoxList>
<asp:TextBox ID="other" runat="server"></asp:TextBox>

inside the for loop

if (chk_list.Items[i].Value == "00")
{
    test +=chk_list.Items[i].Text + other.Text;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号