string s1 = "第一项|第二项|第三项";
string s2 = "value1|value2|value3";
var ar1 = s1.split('|');
var ar2 = s2.split('|');
如何将 a1和a2添加到DataTable中的DEMO表中呢?并将数据绑到DropDownList?

解决方案 »

  1.   

    如何将 ar1ar2添加到DataTable中的DEMO表中呢?并将数据绑到DropDownList?
      

  2.   

    string s1 = "第一项|第二项|第三项";
    string s2 = "value1|value2|value3";
    stringp[] ar1 = s1.split('|');
    string [] ar2 = s2.split('|');
     DataTable table = new DataTable();
               for (int i = 0; i <ar1.Count; i++)
                {
    NewRow = table.NewRow();
      NewRow["t"] =ar1[i].ToString();
     NewRow["v"] =ar1[i].ToString();
                  table.Rows.Add(NewRow);
       }
     this.DropDownList4.DataSource = table;
                this.DropDownList1.DataValueField = "v";
                this.DropDownList1.DataTextField = "t";
                this.DropDownList1.DataBind();
      

  3.   

    谢谢了大哥您打快了,我发个测试通过的
    string s1 = "第一项|第二项|第三项";
    string s2 = "value1|value2|value3";
    var ar1 = s1.Split('|');
    var ar2 = s2.Split('|');
    DataTable table = new DataTable();
    table.Columns.Add("t");
    table.Columns.Add("v");
    for (int i = 0; i < ar1.Length; i++)
    {
    DataRow NewRow = table.NewRow();
    NewRow["t"] = ar1[i].ToString();
    NewRow["v"] = ar1[i].ToString();
    table.Rows.Add(NewRow);
    }
    this.DropDownList1.DataSource = table;
    this.DropDownList1.DataValueField = "v";
    this.DropDownList1.DataTextField = "t";
    this.DropDownList1.DataBind();结贴了