1

选择 | 申请号


我的列表视图中有两列(由以下代码生成),其中第一列是选择链接,而另一列是带有标题应用程序编号的简单列(标题如上所示):

<asp:ListView ID="ListBox1" runat ="server" AutoPostBack="True" 
        onselectedindexchanged="ListBox1_SelectedIndexChanged">
        <LayoutTemplate>
      <table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
         <tr style="background-color: #336699; color: White;">
            <th>Select</th>
            <th>Application No.</th>

         </tr>
         <tbody>
            <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
         </tbody>
      </table>
   </LayoutTemplate>
       <ItemTemplate>
      <tr>
         <td>
            <asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server" />
         </td>
         <td><%# Container.DataItem %></td>

      </tr>
   </ItemTemplate>
   <SelectedItemTemplate>
      <tr style="background-color: #336699; color: White;">
         <td>
            <asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
               ForeColor="White" />
         </td>
         <td><%# Container.DataItem %></td>

      </tr>
   </SelectedItemTemplate>
       </asp:ListView>

现在我想显示字符串 [] 数组中的应用程序编号。我怎么能做到这一点请帮助..?

4

2 回答 2

0
 //are you using datatable as datasource?, if so
        var arr = new[] { "one", "two" };
        var dt = new DataTable();
        dt.Columns.Add("ApplicationNo", typeof(string));
        var i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            dr["ApplicationNo"] = arr[i];
            dt.AcceptChanges();
            i++;
        }

ListBox1.DataSource=dt; ListBox1.DataBind();

于 2013-07-29T09:04:27.990 回答
0

尝试这个,

<asp:ListView ID="mylist" runat="server" 
        onselectedindexchanged="mylist_SelectedIndexChanged">
        <LayoutTemplate>
            <table style="border: solid 2px #336699;" cellspacing="0" cellpadding="3" rules="all">
                <tr style="background-color: #336699; color: White;">
                    <th>
                        Select
                    </th>
                    <th>
                        Application No.
                    </th>
                </tr>
                <tbody>
                    <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
                </tbody>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:LinkButton OnClick="lnkSelect_OnClick"  ID="lnkSelect" Text="Select" CommandArgument='<%# Container.DataItem %>' CommandName="Select" runat="server" />
                </td>
                <td>
                    <%# Container.DataItem %>
                </td>
            </tr>
        </ItemTemplate>
        <SelectedItemTemplate>
            <tr style="background-color: #336699; color: White;">
                <td>
                    <asp:LinkButton ID="lnkSelect" Text="Select" CommandName="Select" runat="server"
                        ForeColor="White" />
                </td>
                <td>
                    <%# Container.DataItem %>
                </td>
            </tr>
        </SelectedItemTemplate>
    </asp:ListView>

IList<string> myList = new List<string>();
        myList.Add("1");
        myList.Add("3");
        myList.Add("2");
        myList.Add("4");


mylist.DataSource = myList;
            mylist.DataBind();

或者

string[] myList = new string[] { "1","2","3" };


            mylist.DataSource = myList;
            mylist.DataBind();



protected void lnkSelect_OnClick(object sender, EventArgs e)
    {
        string val = ((System.Web.UI.WebControls.LinkButton)(sender)).CommandArgument;
    }
于 2013-07-29T09:18:53.703 回答