int i ;
for i=0 to DDL1.Items.count-1
if DDL1.Items(i).Value=((Label)(e.Item.Cells[2].FindControl("Label3"))).Text then
DDL1.item(i).selected=true
else
DDL1.Item(i).selected=false
end if
Next

解决方案 »

  1.   

    使用模板列:
    <EditItemTemplate>
     <asp:DropDownList id=DropDownList1 runat="server" DataSource="<%# DataSet31 %>" SelectedIndex='<%# GetStateIndex(Container.DataItem("零部件种类")) %>' DataTextField="myname" DataValueField="myname">
     </asp:DropDownList>
    </EditItemTemplate>
    其中的DataSet31就是SELECT myid, myname FROM codeid的简单数据集然后数据绑定:
        Public Function GetStateIndex(ByVal StateName As String) As Integer
            Dim StateIndex As Hashtable
            Dim mynames As String
            StateIndex = New Hashtable()
            Dim myTable As DataTable = DataSet31.Tables("codeid")
            Dim I, J As Integer
            For I = 0 To myTable.Rows.Count - 1
                mynames = myTable.Rows(I).Item(1)
                StateIndex(mynames) = I
            Next        If StateIndex(StateName) <> Nothing Then
                Return CInt(StateIndex(StateName))
            Else
                Return 0
            End If
        End Function
      

  2.   

    写个类似下面功能的函数:
    public int getSelectedIndex(string str)
    {
    int idx=0;
    dsEditData1=(dsEditData)Session["dsEditData1"];
    for(int i=0;i<dsEditData1.EDIT_DATAlIST.Rows.Count;i++)
    {
    dsEditData.EDIT_DATAlISTRow editRow=(dsEditData.EDIT_DATAlISTRow)dsEditData1.EDIT_DATAlIST.Rows[i];
    string dataStr=editRow.editValue;
    if(dataStr==str)
    {
    idx=i;
    break;
    }
    }
    return idx;
    }
    然后在HTML中:
    <EditItemTemplate>
    <asp:DropDownList id=DropDownList1 runat="server" DataMember="EDIT_DATAlIST" DataSource="<%# dsEditData1 %>" Width="93px" DataTextField="editData" DataValueField="editValue" SelectedIndex='<%# getSelectedIndex(DataBinder.Eval(Container, "DataItem.personationid").ToString()) %>'>
    </asp:DropDownList>
    </EditItemTemplate>
      

  3.   

    把最后一句换成:
    for (int i=0;i<DDL1.Items.Count;i++)
    {
         if (DDL1.Items[i].Value==dept1)
    {
                 DDL1.SelectedIndex=i;
        break;
    }
    }