473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

dropdown in fully editable datagrid

I've been grappling with this for days and hope someone has some suggestions.
I have a datagrid that I'd like to place entirely in edit mode so people
don't have to update data row by row. I've accomplished this but my dropdown
list is no longer bound to the data source. It just defaults to the first
item in the dropdown list source table. Thanks!

<asp:TemplateColumn HeaderText="COMPANY">
<ItemTemplate>
<asp:Label runat="server"
id="lblAccountID"
Visible="False"
Text='<%# DataBinder.Eval(Container.DataItem, "AccountID") %>'/>
<asp:DropDownList id=ddlCompany runat="server"
DataValueField="CompanyID"
DataTextField="CompanyDesc"
OnPreRender="SetDropDownIndex"
DataSource="<%# BindTheCountry() %>"
SelectedIndex='<%# GetSelIndex(Container.DataItem("AccountID")) %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>

The BindTheCountry() sub in my code behind (I know, it's named awkwardly) is
below. This is just a lookup table for the dropdown list.

Public Function BindTheCountry()
Dim _SqlConnection As New SqlConnection(strConn)
Dim cmdCustomers As SqlCommand = New SqlCommand("SELECT Statement",
_SqlConnection)
cmdCustomers.CommandType = CommandType.Text
_SqlConnection.Open()
Return cmdCustomers.ExecuteReader(CommandBehavior.CloseCo nnection)
End Function

The data in the SQL table I'm trying to bind to is also in the code behind:
Public Sub BindCompetition(ByVal _ID As String)
Dim _SqlCompetition As String = "SELECT Statement WHERE AccountID =
" & _ID & ""
Dim _Ds As New DataSet
Dim _SqlCompetitionConnection As New SqlConnection(strConn)
Dim _SqlCompetitionCommand As New SqlCommand(_SqlCompetition,
_SqlCompetitionConnection)
Dim _SqlCompetitionDataAdapter As New
SqlDataAdapter(_SqlCompetitionCommand)
_SqlCompetitionConnection.Open()
_SqlCompetitionDataAdapter.Fill(_Ds)
dgCompetitorStatus.DataSource = _Ds
dgCompetitorStatus.DataBind()
End Sub

Jul 27 '06 #1
0 923

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kilic Beg via .NET 247 | last post by:
Hi, I am having trouble adding a dropdown to DataGrid at runtime. I create all boundColumns and the TemplateColumn for the dropdown at runtime. The dropdown has a different datasource then the...
0
by: Andla Rand | last post by:
Hi, Could you help me to understand how datagrid works. I'm trying to make a datagrid editable. Now most of the tutorials I read says that i should turn the Enable ViewState off. Why is that? ...
0
by: Philip Townsend | last post by:
I have a datagrid that contains a dropdown list that is part of an EditItemTemplate. I need to run some code when the dropdown list builds in order to preselect an item in the list. Preselecting...
4
by: Stephan Bour | last post by:
Hi, I have a datagrid databound to a SQL query. I'd like to allow editing of some columns but not all. Is there a way to turn off the conversion of the datagrid cells to textboxes for some columns...
1
by: Philip Townsend | last post by:
I have a datagrid that contains a dropdown list that is part of an EditItemTemplate. I need to run some code when the dropdown list builds in order to preselect an item in the list. Preselecting...
1
by: Larry Rekow | last post by:
Using: MS SQL, VS.Net 2003, VB.Net Each night our SQL db imports two text file reports into two tables: Table 1 has info on various shipments (shipment number, date, destination, etc.) Table 2...
1
by: vishnu | last post by:
Hi, I have a fully editable datagrid which has dropdownlist in two columns. Now i have to bind the dropdown in the second column based on the value selected in the dropdown in the firstcolumn. so...
0
by: juustagirl | last post by:
There is only one editable field on my datagrid ... a combo box. The data displays correctly. I have a button to make all the changes .... but they are never written back to my Access database....
4
by: Paul | last post by:
Hi all, I have a page that has a form on it which has a dropdown list on it. It connect to an sql database and populate the list. What I would like to do is make the list editable so that if the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.