DataGrid DropDown Template Column

G

Guest

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
 
G

Guest

It took the better part of a weekend but I was able to somehow piece this
together. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top