列表框的选定项目要更改 [英] Selected item of list box wants to be changed

查看:49
本文介绍了列表框的选定项目要更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp列表框中有一个项目列表,我传递了一个在列表框中列出的值,然后希望在列表框中选择该项目.

请帮我怎么做.

预先感谢您的帮助..

I have a list of items in the asp list box, and I am passing a value which is listed in the list box, then that item wants to be selected in the list box.

Please help me how to do this.

Advance thanks for helping..

推荐答案

<asp:ListBox ID="ListBox1" runat="server">
            <asp:ListItem Value="1">Add</asp:ListItem>
            <asp:ListItem Value="2">Sub</asp:ListItem>
            <asp:ListItem Value="3">Mul</asp:ListItem>
            <asp:ListItem Value="4">Div</asp:ListItem>
        </asp:ListBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />









protected void Button1_Click(object sender, EventArgs e)
        {
            ListItem l = new ListItem("Sub", "2");
            ListBox1.SelectedIndex = ListBox1.Items.IndexOf(l);
        }




希望这段代码对您有帮助.....




Hope this code may help you.....


您好,

如果需要从列表框中选择"Libish",请使用以下代码.

Hello,

If you need to select "Libish" from the list box, use the following code.

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <asp:ListBox ID="ListBox1" runat="server">
        <asp:ListItem>vinod</asp:ListItem>
        <asp:ListItem>Alex</asp:ListItem>
        <asp:ListItem>Libish</asp:ListItem>
    </asp:ListBox>

protected void Button1_Click(object sender, EventArgs e)
{
        ListBox1.SelectedValue = "Libish";
}



谢谢!!!



Thanks!!!


这篇关于列表框的选定项目要更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆