Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down List in Datagrid Template Column

Status
Not open for further replies.

jzelhart

Programmer
Feb 10, 2003
469
US
How do I refer to the Drop Down List Control so that I can fill the list with data?

HTML for the EditItemTemplate:
<EditItemTemplate> <asp:DropDownList id=&quot;cboClientCityState&quot; runat=&quot;server&quot; SelectedIndex='<%# DataBinder.Eval(Container, &quot;DataItem.ClientCityStateNotation_VC&quot;) %>' Font-Size=&quot;8pt&quot; Font-Names=&quot;Arial&quot; Width=&quot;425px&quot; Font-Bold=&quot;True&quot;>
</asp:DropDownList>
</EditItemTemplate>


Hope everyone is having a great day!

Thanks - Jennifer
 
cboClientCityState.Items.Add(&quot;Description&quot;) in your code-behind

 
I need to fill it with a Dataset in the code behind.

If the asp:DropDownList is on the page and not in the datagrid. Then the following code works.

lblError.Text = &quot;&quot;
Try
Dim sb As SQLBean = New SQLBean
Dim ds As DataSet
ds = sb.getOtherLogins()
cboExpTypeAdd.DataSource = ds.Tables(0).DefaultView
cboExpTypeAdd.DataBind()

Catch ex As Exception
lblError.Text = &quot;A problem was found loading the Expense Types. Please try again.&quot;
End Try

For the item included in the EditItemTemplate area, I can't refer to the cbo field directly.

Any help would be appreciated.

Thanks,

Jennifer

Hope everyone is having a great day!

Thanks - Jennifer
 
Found this one...

<asp:ListBox id=lstClientCityStateEdit runat=&quot;server&quot; Width=&quot;338px&quot; DataValueField=&quot;CustomerName_VC&quot; DataTextField=&quot;CustomerName_VC&quot; SelectedIndex='<%# GetCustNameIndex(Container.DataItem(&quot;ClientCityStateNotation_VC&quot;)) %>' DataSource=&quot;<%# GetCustNameEdit() %>&quot; Rows=&quot;4&quot;>
</asp:ListBox>


Function GetCustNameEdit() As DataSet
Try
Dim sb As SQLBean = New SQLBean
Dim strSQL As String
strSQL = &quot;SELECT DISTINCT TOP 100 PERCENT CustomerName_VC FROM dbo.ks_Customer_T ORDER BY CustomerName_VC&quot;
ds = sb.getClients(strSQL)
Catch ex As Exception
lblError.Text = Trim(lblError.Text & &quot; A problem was found loading the Customer List for Editing. Please try again.&quot;)
End Try

Return ds

End Function

Function GetCustNameIndex(ByVal strName As String) As Integer
Dim i As Integer
Dim dt As DataTable = ds.Tables(&quot;Returned&quot;)
For i = 0 To dt.Rows.Count - 1
If strName = dt.Rows(i)(&quot;CustomerName_VC&quot;) Then
Return i
End If
Next i
End Function

Thought I would add this. Hope it helps someone else.

Jennifer

Hope everyone is having a great day!

Thanks - Jennifer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top