GridView的HeaderText [英] HeaderText of GridView

查看:140
本文介绍了GridView的HeaderText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



单击按钮后,如何排序Listbox(1和2)项,然后将Listbox(2)排序为gridview中列的标题文本.

ListBox1 ListBox2
1个Aaa
2 bbb
5 ccc
4 eee
6 ddd
3 fff

GridView(列标题文本)

aaa bbb fff eee ccc ddd

希望它清楚.

Hi,

How can I sort Listbox(1 and 2) Items then Listbox(2) sorted to be header text of columns in gridview after a button is click.

ListBox1 ListBox2
1 aaa
2 bbb
5 ccc
4 eee
6 ddd
3 fff

GridView (column headertext)

aaa bbb fff eee ccc ddd

hope its clear. thanks to provide code.

推荐答案

首先是简短的listbox1,然后是简短的listbox2,然后将它们组合起来.
Firstly short listbox1 and after that short listbox2 and after that combine them.


<%@ Page Language="C#" AutoEventWireup="true"%>

<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            List<ListItem> list = new List<ListItem>(ListBox1.Items.Cast<ListItem>());

            //sort list item alphabetixcally
            listlist = list.OrderBy(x=> x.Text).ToList<ListItem>();

            ListBox1.Items.Clear();
            ListBox1.Items.AddRange(list.ToArray<ListItem>());
        }
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = "you selected....<br />";
        Label1.Text += "item: " + ListBox1.SelectedItem.Text;
        Label1.Text += "<br />value: " + ListBox1.SelectedItem.Value;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>asp.net listbox sort alphabetically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">
            asp.net example - listbox sort alphabetically
        </h2>
        <hr width="550" align="left" color="Gainsboro" />
        <asp:Label

            ID="Label1"

            runat="server"

            Text="select an item from ListBox."

            Font-Size="X-Large"

            Width="350"

            >
        </asp:Label>
        <br /><br />
        <asp:ListBox

            ID="ListBox1"

            runat="server"

            AutoPostBack="true"

            Width="350"

            Font-Size="X-Large"

            SelectionMode="Single"

            Height="200"

            OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"

            >
            <asp:ListItem Text="Rufous-tailed Plantcutter" Value="1"></asp:ListItem>
            <asp:ListItem Text="Andean C**k-of-the-rock" Value="2"></asp:ListItem>
            <asp:ListItem Text="Yellow-bellied Elaenia" Value="3"></asp:ListItem>
            <asp:ListItem Text="Grey-hooded Flycatcher" Value="4"></asp:ListItem>
            <asp:ListItem Text="Cliff Flycatcher" Value="5"></asp:ListItem>
        </asp:ListBox>
    </div>
    </form>
</body>
</html>






这个例子可能对您有帮助






this example may help you


private void SortListBox()

   {

       ArrayList ListBoxArray = new ArrayList();

       int i = 0;



       while (i < CarNameListBox.Items.Count)

       {

           ListBoxArray.Add(CarNameListBox.Items[i].Value);

           ++i;

       }

       CarNameListBox.Items.Clear();

       ListBoxArray.Sort();

       i = 0;

       while(ListBoxArray.Count > i)

       {

           CarNameListBox.Items.Add(ListBoxArray[i].ToString());

           ++i;

       }

   }




您也可以应用此




you can also apply this


这篇关于GridView的HeaderText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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