473,497 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid DropDown Template Column

I'm new to Web development so I'm doing some bootstrapping and would really
appreciate any help. Been grappling with this for days and am utterly
confused by all the information on the web. I have a DataGrid with customer
information. The last column is a dropdown template column that allows our
reps to assign an attribute to the account i.e. small, medium, large or
something like that. Here's where I'm stuck 1) I can't get the drop down list
to populate 2) Once populated, I'm not really sure how to update the sql
table where the customer information is stored.

The sql table that I'm updating is called AdHocAccountTypes and has two int
fields: AccountID, AccountTypeID

The sql table that should poplulate the dropdown is called
AdHocReaAccountTypes and has two fields:
AccountTypeID, int
AccountTypeDesc, VarChar(16)

Here's my HTML:

<Columns>
<asp:BoundColumn DataField="AccountID" SortExpression="AccountID"
HeaderText="ACCOUNT #"></asp:BoundColumn>
<asp:BoundColumn DataField="ACCDESC" SortExpression="ACCDESC"
HeaderText="ACCOUNT NAME"></asp:BoundColumn>
<asp:BoundColumn DataField="CITY" SortExpression="CITY"
HeaderText="CITY"></asp:BoundColumn>
<asp:BoundColumn DataField="STATE" SortExpression="STATE"
HeaderText="ST"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="CHOOSE ACCOUNT TYPE">
<ItemTemplate>
<asp:DropDownList id=ddlAccountType1 runat="server"
DataValueField="AccountTypeID" DataTextField="AccountTypeDesc"
DataSource="<%# FillddlAccountType %>">
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id=ddlAccountType2 runat="server"
DataValueField="AccountTypeID" DataTextField="AccountTypeDesc"
DataSource="<%# FillddlAccountType %>">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
</Columns>

Here's my code behind:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class AccountList
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected myComponent As New Component1
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents ddlTerritory As
System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlAccountTypeID1 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Dim strConnBizPlan As String =
ConfigurationSettings.AppSettings("strConnBizPlan" )
Dim strConnNewProd As String =
ConfigurationSettings.AppSettings("strConnNewProd" )

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Call FillddlTerritory()
Call FillddlAccountType()
End If
End Sub

Sub FillddlTerritory()
Dim _SqlTerritory As String = "EXECUTE spGetTerritory"
Dim _Ds As New DataSet
Dim _SqlConnection As New SqlConnection(strConnNewProd)
Dim _SqlCommand As New SqlCommand(_SqlTerritory, _SqlConnection)
Dim _SqlDataAdapter As New SqlDataAdapter(_SqlCommand)
_SqlConnection.Open()
_SqlDataAdapter.Fill(_Ds)
ddlTerritory.DataValueField = "TerritoryID"
ddlTerritory.DataTextField = "Territory"
ddlTerritory.DataSource = _Ds
ddlTerritory.DataBind()
End Sub

Public Sub FillddlAccountType()
Dim _SqlAccountType As String = "SELECT * From AdHocReaAccountTypes"
Dim _Ds As New DataSet
Dim _SqlConnection As New SqlConnection(strConnBizPlan)
Dim _SqlCommand As New SqlCommand(_SqlAccountType, _SqlConnection)
Dim _SqlDataAdapter As New SqlDataAdapter(_SqlCommand)
_SqlConnection.Open()
_SqlDataAdapter.Fill(_Ds)
ddlAccountTypeID1.DataValueField = "AccountTypeID"
ddlAccountTypeID1.DataTextField = "AccountTypeDesc"
ddlAccountTypeID1.DataSource = _Ds
ddlAccountTypeID1.DataBind()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strTerritory_ID As String = ddlTerritory.SelectedValue
BindData(strTerritory_ID)
End Sub

Private Sub BindData(ByVal _ID As String)
Dim _SqlAccounts As String = "Select AccountID, AccountTypeID,
ACCDESC, CITY, STATE from ACCLIST INNER JOIN AdHocAccountTypes ON
ACCLIST.ACCID = AdHocAccountTypes.AccountID AND TERID = " & _ID & " ORDER BY
ACCDESC ASC "
Dim _Ds As New DataSet
Dim _SqlConnection As New SqlConnection(strConnBizPlan)
Dim _SqlCommand As New SqlCommand(_SqlAccounts, _SqlConnection)
Dim _SqlDataAdapter As New SqlDataAdapter(_SqlCommand)
_SqlConnection.Open()
_SqlDataAdapter.Fill(_Ds)
DataGrid1.DataSource = _Ds
DataGrid1.DataBind()
End Sub
End Class
Dec 9 '05 #1
1 1456
It took the better part of a weekend but I was able to somehow piece this
together. Thanks.

"Mike C" wrote:
I'm new to Web development so I'm doing some bootstrapping and would really
appreciate any help. Been grappling with this for days and am utterly
confused by all the information on the web. I have a DataGrid with customer
information. The last column is a dropdown template column that allows our
reps to assign an attribute to the account i.e. small, medium, large or
something like that. Here's where I'm stuck 1) I can't get the drop down list
to populate 2) Once populated, I'm not really sure how to update the sql
table where the customer information is stored.

The sql table that I'm updating is called AdHocAccountTypes and has two int
fields: AccountID, AccountTypeID

The sql table that should poplulate the dropdown is called
AdHocReaAccountTypes and has two fields:
AccountTypeID, int
AccountTypeDesc, VarChar(16)

Here's my HTML:

<Columns>
<asp:BoundColumn DataField="AccountID" SortExpression="AccountID"
HeaderText="ACCOUNT #"></asp:BoundColumn>
<asp:BoundColumn DataField="ACCDESC" SortExpression="ACCDESC"
HeaderText="ACCOUNT NAME"></asp:BoundColumn>
<asp:BoundColumn DataField="CITY" SortExpression="CITY"
HeaderText="CITY"></asp:BoundColumn>
<asp:BoundColumn DataField="STATE" SortExpression="STATE"
HeaderText="ST"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="CHOOSE ACCOUNT TYPE">
<ItemTemplate>
<asp:DropDownList id=ddlAccountType1 runat="server"
DataValueField="AccountTypeID" DataTextField="AccountTypeDesc"
DataSource="<%# FillddlAccountType %>">
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id=ddlAccountType2 runat="server"
DataValueField="AccountTypeID" DataTextField="AccountTypeDesc"
DataSource="<%# FillddlAccountType %>">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
</Columns>

Here's my code behind:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class AccountList
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected myComponent As New Component1
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents ddlTerritory As
System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlAccountTypeID1 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Dim strConnBizPlan As String =
ConfigurationSettings.AppSettings("strConnBizPlan" )
Dim strConnNewProd As String =
ConfigurationSettings.AppSettings("strConnNewProd" )

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Call FillddlTerritory()
Call FillddlAccountType()
End If
End Sub

Sub FillddlTerritory()
Dim _SqlTerritory As String = "EXECUTE spGetTerritory"
Dim _Ds As New DataSet
Dim _SqlConnection As New SqlConnection(strConnNewProd)
Dim _SqlCommand As New SqlCommand(_SqlTerritory, _SqlConnection)
Dim _SqlDataAdapter As New SqlDataAdapter(_SqlCommand)
_SqlConnection.Open()
_SqlDataAdapter.Fill(_Ds)
ddlTerritory.DataValueField = "TerritoryID"
ddlTerritory.DataTextField = "Territory"
ddlTerritory.DataSource = _Ds
ddlTerritory.DataBind()
End Sub

Public Sub FillddlAccountType()
Dim _SqlAccountType As String = "SELECT * From AdHocReaAccountTypes"
Dim _Ds As New DataSet
Dim _SqlConnection As New SqlConnection(strConnBizPlan)
Dim _SqlCommand As New SqlCommand(_SqlAccountType, _SqlConnection)
Dim _SqlDataAdapter As New SqlDataAdapter(_SqlCommand)
_SqlConnection.Open()
_SqlDataAdapter.Fill(_Ds)
ddlAccountTypeID1.DataValueField = "AccountTypeID"
ddlAccountTypeID1.DataTextField = "AccountTypeDesc"
ddlAccountTypeID1.DataSource = _Ds
ddlAccountTypeID1.DataBind()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strTerritory_ID As String = ddlTerritory.SelectedValue
BindData(strTerritory_ID)
End Sub

Private Sub BindData(ByVal _ID As String)
Dim _SqlAccounts As String = "Select AccountID, AccountTypeID,
ACCDESC, CITY, STATE from ACCLIST INNER JOIN AdHocAccountTypes ON
ACCLIST.ACCID = AdHocAccountTypes.AccountID AND TERID = " & _ID & " ORDER BY
ACCDESC ASC "
Dim _Ds As New DataSet
Dim _SqlConnection As New SqlConnection(strConnBizPlan)
Dim _SqlCommand As New SqlCommand(_SqlAccounts, _SqlConnection)
Dim _SqlDataAdapter As New SqlDataAdapter(_SqlCommand)
_SqlConnection.Open()
_SqlDataAdapter.Fill(_Ds)
DataGrid1.DataSource = _Ds
DataGrid1.DataBind()
End Sub
End Class

Dec 12 '05 #2

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

Similar topics

1
1622
by: HalaszJ | last post by:
Is there no work around for this? >-----Original Message----- >I have asked this question on about every board I can >think of and I have yet to get an answer, so If anyone >would know I...
1
1533
by: Deepa | last post by:
I am doing an ASP.Net application wherein I have a datagrid which I need to populate dynamically. The grid has 5 rows and two columns. In the 2nd col I need to insert dropdown boxes. I'll have to...
4
1722
by: ShadowsOfTheBeast | last post by:
hi oliver thanks for your help i kinda figured that out minutes afterwards...but what i am actually trying to do is this: i have a listbox control that gets its data from another listbox (hence...
1
5231
by: SamIAm | last post by:
Hi I have a DataGrid called dgTraders 1 of the columns is a template column and this column has a Dropdown box in its HeaderTemplate section. The Dropdown box is called selCities. How do I...
4
5958
by: Richard Roche | last post by:
Is it possible to use a drop combo instead of a text box when using the EditCommand in the Datagrid? Many table columns are bound to 'lookup' tables, user's don't care about the foreign keys,...
5
5114
by: Paul | last post by:
Hi I need to change the text value of a dropdown list box that is in a template column of a data grid but was not sure how to access it, probably something like datagrid1.control.dropdownlist.text...
3
1791
by: Richard | last post by:
I've seen articles on GotDotNet and elsewhere on how to put a ddl in a datagrid, and have been able to implement this technique. For a new item, among the datagrid columns there is the one ddl for...
6
5383
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
0
2893
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
6993
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
7197
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...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.