Click here to Skip to main content
15,887,083 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Passing custom object to web service Pin
nlarson1111-May-07 11:07
nlarson1111-May-07 11:07 
GeneralRe: Passing custom object to web service Pin
BobsAfro14-May-07 3:26
BobsAfro14-May-07 3:26 
GeneralRe: Passing custom object to web service Pin
nlarson1114-May-07 3:41
nlarson1114-May-07 3:41 
GeneralRe: Passing custom object to web service Pin
BobsAfro14-May-07 3:48
BobsAfro14-May-07 3:48 
GeneralRe: Passing custom object to web service Pin
BobsAfro14-May-07 3:53
BobsAfro14-May-07 3:53 
GeneralRe: Passing custom object to web service Pin
nlarson1114-May-07 3:54
nlarson1114-May-07 3:54 
GeneralRe: Passing custom object to web service Pin
BobsAfro14-May-07 3:59
BobsAfro14-May-07 3:59 
QuestionDatagrid dropdownlist, populated from Access database. [modified] Pin
robw188810-May-07 1:06
robw188810-May-07 1:06 
Hi all,

First of all I'll apologise in advance! I'm very new to this and have been trying to learn through books and what I can pick up on the net so I'm hoping someone can help me understand where I'm going wrong with the following...

I've set up a datagrid which works perfectly when I use textboxes, however I'm trying to limit user choice by adding dropdownlists to the datagrid. I get as far as clicking to edit the field and get the following error:

---------------------------
System.IndexOutOfRangeException: StatusID

Source Error:


Line 345:
Line 346: <edititemtemplate>
Line 347: <asp:dropdownlist id="ddlStatusctrl" runat="server"
line="" 348:="" datatextfield="Status" 349:="" datavaluefield="StatusID"
=""
----------------------------

my="" coding="" for="" the="" dropdownlist="" is="" as="" follows:

="" <asp:templatecolumn="">
<headertemplate>
Status

<itemtemplate>
<%# Container.DataItem("Status") %>

<edititemtemplate>
<asp:dropdownlist id="ddlStatusctrl" runat="server"
="" datatextfield="Status" datavaluefield="StatusID" datasource="<%# GetStatus() %>" selectedindex="<%# GetSelectedIndex(Container.DataItem("StatusID")) %>">




and VB code is :

to populate the dataset ('Dim DS as DataSet = New DataSet()' declared globally) ...

Function GetStatus() as DataSet

Dim DBConn as OleDbConnection
Dim DBCommand as OleDbDataAdapter


DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("data/Auto_log.mdb") & ";")
DBCommand = New OleDbDataAdapter("SELECT StatusID, Status from Status ORDER BY Status", DBConn)


DBCommand.Fill(DS, "Status")
DBConn.Close()

Return DS


End Function
----------------
to get selected index -

Function GetSelectedIndex(ByVal StatusID As String) As Integer
'Loop through the DataSet DS
Dim iLoop As Integer
Dim DT As DataTable = DS.Tables("Status")
For iLoop = 0 To DT.Rows.Count - 1
If StatusID = DT.Rows(iLoop)("StatusID").ToString Then
Return iLoop
End If
Next iLoop
End Function
-----------

... & to update the database (cut to show coding related to ddl)-

Sub dg_Update(s As Object, e As DataGridCommandEventArgs)

Dim ddlStatus As DropDownList = FindControl("ddlStatusctrl")

strCmd = "UPDATE AutomationHist SET System=@System, Status=@ddlStatus, ProgramNo=@ProgramNo, VersionNo=@VersionNo, LastJobNo=@LastJobNo, Date_Last_Amended=@Date_Last_AmendedParam, Date_Authorised=@Date_AuthorisedParam, Coded_by=@Coded_by, Location=@Location, Calculation=@Calculation, Writeback=@Writeback, Letter_output=@Letter_output, Exceptions=@Exceptions, Comments=@Comments WHERE Primary_Key=@Primary_Key"

objCmd.Parameters.Add("@ddlStatus", ddlStatus)


objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()

dgAutomationHist.EditItemIndex = -1
BindData()
End Sub

------------------

Thanks very much in advance...

Smile | :)




-- modified at 7:21 Thursday 10th May, 2007


-- modified at 7:27 Thursday 10th May, 2007


-- modified at 7:41 Thursday 10th May, 2007

Robster

Questionexlude from column ordering a field Pin
sal219-May-07 23:53
sal219-May-07 23:53 
AnswerRe: exlude from column ordering a field Pin
nlarson1110-May-07 4:14
nlarson1110-May-07 4:14 
QuestionTray Icon Pin
nitin_ion9-May-07 22:32
nitin_ion9-May-07 22:32 
AnswerRe: Tray Icon Pin
Sonia Gupta9-May-07 23:35
Sonia Gupta9-May-07 23:35 
GeneralRe: Tray Icon Pin
nitin_ion9-May-07 23:57
nitin_ion9-May-07 23:57 
GeneralRe: Tray Icon Pin
Sonia Gupta10-May-07 0:10
Sonia Gupta10-May-07 0:10 
AnswerRe: Tray Icon Pin
P P Vilsad10-May-07 17:51
P P Vilsad10-May-07 17:51 
AnswerRe: Tray Icon Pin
kubben10-May-07 4:40
kubben10-May-07 4:40 
GeneralRe: Tray Icon Pin
Sonia Gupta10-May-07 18:05
Sonia Gupta10-May-07 18:05 
QuestionWorkflow Pin
s.a.Rahman9-May-07 21:33
s.a.Rahman9-May-07 21:33 
AnswerRe: Workflow Pin
Christian Graus10-May-07 2:20
protectorChristian Graus10-May-07 2:20 
Questiontotal days in three months [modified] Pin
Sonia Gupta9-May-07 21:32
Sonia Gupta9-May-07 21:32 
AnswerRe: total days in three months Pin
Arun.Immanuel9-May-07 22:51
Arun.Immanuel9-May-07 22:51 
GeneralRe: total days in three months Pin
andyharman9-May-07 23:23
professionalandyharman9-May-07 23:23 
GeneralRe: total days in three months Pin
Arun.Immanuel10-May-07 1:32
Arun.Immanuel10-May-07 1:32 
AnswerRe: total days in three months Pin
Christian Graus10-May-07 2:19
protectorChristian Graus10-May-07 2:19 
AnswerRe: total days in three months Pin
klaydze10-May-07 17:15
klaydze10-May-07 17:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.