wessamzeidan
Junior Contributor
You're welcomed. But can you tell us what you did??
[COLOR=Blue]<asp:TemplateColumn HeaderText="Modem">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"Modem") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id=Dropdownlist2 datasource='<%# GetDataSet("Modem_Catalog","Name") %>' Runat="server" DataValueField="Name" DataTextField="Name" SelectedIndex='<%#GetSelectedIndex(Container.Dataitem("Modem"),"Modem_Catalog","Name") %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn[/COLOR]>
[COLOR=Blue]Public Function GetSelectedIndex(ByVal item As String, ByVal table As String, ByVal col As String) As Integer
hTable(table) = item ' [COLOR=YellowGreen]this is to put string instead of dropdownlist while in edit mode[/COLOR]
'loop through the dataset: ddlDataSet
Dim i As Integer
Dim dt As DataTable = ddldataset.Tables(table)
For i = 0 To dt.Rows.Count - 1
If Trim(item) = Trim(dt.Rows(i)(col).ToString()) Then
Return i
End If
Next
End Function[/COLOR]
[COLOR=Blue]Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
CType(e.Item.Cells(5).FindControl("Dropdownlist2"), DropDownList).Visible = False [COLOR=YellowGreen]'hide the dropdownlist[/COLOR]
e.Item.Cells(5).Text = hTable("Modem_Catalog") [COLOR=YellowGreen]'put the lastr selected string instead of the dropdown list (in edit mode)[/COLOR]
End If
End Sub[/COLOR]