Can someone tell me how I get the correct selected office in my drop down
list when I enter edit mode. At the moment it just defaults to the office at
the top of the drop down list rather than picking the office that has
actually been selected previously!
I hope this is clear...
Here is my code...
Thanks
''''''''''''''''''''''Problem - not reading the correct office when in
edit mode
Function GetSelectedIndex(ByVal PageID As String) As Integer
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("SelectOffice", Myconn)
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
If myReader.HasRows Then
Do While myReader.Read()
Console.WriteLine(vbTab & "{0}" & vbTab & "{1}",
myReader.GetInt32(0), myReader.GetString(1))
Loop
Else
Console.WriteLine("No rows returned.")
End If
myReader.Close()
Myconn.Close()
End Function
Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)
Dim pageID = CInt(CType(e.Item.FindControl("pageID"), TextBox).Text)
'Construct the Database Connection
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("SelectOffice", Myconn)
If e.Item.ItemType = ListItemType.EditItem Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names
add_Office = CType(e.Item.FindControl("DDLeditOffice"),
DropDownList)
add_Office.DataSource =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
add_Office.DataTextField = "offName"
add_Office.DataValueField = "officeID"
add_Office.DataBind()
add_Office.SelectedIndex = GetSelectedIndex(pageID)
Myconn.Close()
Else
If e.Item.ItemType = ListItemType.Footer Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names
add_Office = CType(e.Item.FindControl("DDLaddOffice"),
DropDownList)
add_Office.DataSource =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
add_Office.DataTextField = "offName"
add_Office.DataValueField = "officeID"
add_Office.DataBind()
add_Office.Items.Insert(0, "Select One")
add_Office.Items.FindByText("Select One").Value = 0 'insert
don't create a value, but we need a value during defaults
add_Office.SelectedIndex = 0
Myconn.Close()
End If
End If
End Sub 3 4356
Hi Tim,
Don't have time to test your code, but just in case.... this issue is often
caused by incorrectly rebinding to the data on postback. Make sure you are
wrapping the function in If not ispostback
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:B8**********************************@microsof t.com... Can someone tell me how I get the correct selected office in my drop down list when I enter edit mode. At the moment it just defaults to the office at the top of the drop down list rather than picking the office that has actually been selected previously!
I hope this is clear...
Here is my code...
Thanks
''''''''''''''''''''''Problem - not reading the correct office when in edit mode Function GetSelectedIndex(ByVal PageID As String) As Integer
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn")) Dim cmd As New SqlCommand("SelectOffice", Myconn) cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
If myReader.HasRows Then Do While myReader.Read() Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1)) Loop Else Console.WriteLine("No rows returned.") End If myReader.Close()
Myconn.Close() End Function
Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
Dim pageID = CInt(CType(e.Item.FindControl("pageID"), TextBox).Text)
'Construct the Database Connection Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn")) Dim cmd As New SqlCommand("SelectOffice", Myconn)
If e.Item.ItemType = ListItemType.EditItem Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names add_Office = CType(e.Item.FindControl("DDLeditOffice"), DropDownList) add_Office.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) add_Office.DataTextField = "offName" add_Office.DataValueField = "officeID" add_Office.DataBind() add_Office.SelectedIndex = GetSelectedIndex(pageID) Myconn.Close() Else
If e.Item.ItemType = ListItemType.Footer Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names add_Office = CType(e.Item.FindControl("DDLaddOffice"), DropDownList) add_Office.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) add_Office.DataTextField = "offName" add_Office.DataValueField = "officeID" add_Office.DataBind() add_Office.Items.Insert(0, "Select One") add_Office.Items.FindByText("Select One").Value = 0 'insert don't create a value, but we need a value during defaults add_Office.SelectedIndex = 0 Myconn.Close() End If End If End Sub
Hi Ken thanks for the response but I don't think this is the problem!
I would appritiate any other suggestions!
Thanks
"Ken Cox [Microsoft MVP]" wrote: Hi Tim,
Don't have time to test your code, but just in case.... this issue is often caused by incorrectly rebinding to the data on postback. Make sure you are wrapping the function in If not ispostback
"Tim::.." <myatix_at_hotmail.com> wrote in message news:B8**********************************@microsof t.com... Can someone tell me how I get the correct selected office in my drop down list when I enter edit mode. At the moment it just defaults to the office at the top of the drop down list rather than picking the office that has actually been selected previously!
I hope this is clear...
Here is my code...
Thanks
''''''''''''''''''''''Problem - not reading the correct office when in edit mode Function GetSelectedIndex(ByVal PageID As String) As Integer
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn")) Dim cmd As New SqlCommand("SelectOffice", Myconn) cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
If myReader.HasRows Then Do While myReader.Read() Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1)) Loop Else Console.WriteLine("No rows returned.") End If myReader.Close()
Myconn.Close() End Function
Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
Dim pageID = CInt(CType(e.Item.FindControl("pageID"), TextBox).Text)
'Construct the Database Connection Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn")) Dim cmd As New SqlCommand("SelectOffice", Myconn)
If e.Item.ItemType = ListItemType.EditItem Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names add_Office = CType(e.Item.FindControl("DDLeditOffice"), DropDownList) add_Office.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) add_Office.DataTextField = "offName" add_Office.DataValueField = "officeID" add_Office.DataBind() add_Office.SelectedIndex = GetSelectedIndex(pageID) Myconn.Close() Else
If e.Item.ItemType = ListItemType.Footer Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names add_Office = CType(e.Item.FindControl("DDLaddOffice"), DropDownList) add_Office.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) add_Office.DataTextField = "offName" add_Office.DataValueField = "officeID" add_Office.DataBind() add_Office.Items.Insert(0, "Select One") add_Office.Items.FindByText("Select One").Value = 0 'insert don't create a value, but we need a value during defaults add_Office.SelectedIndex = 0 Myconn.Close() End If End If End Sub
Check out "Displaying a Drop-Down List in Edit Mode" section in this
article, http://msdn.microsoft.com/library/en...ngmultiplerows
--
-Saravana http://dotnetjunkies.com/WebLog/saravana/ www.ExtremeExperts.com
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:B8**********************************@microsof t.com... Can someone tell me how I get the correct selected office in my drop down list when I enter edit mode. At the moment it just defaults to the office
at the top of the drop down list rather than picking the office that has actually been selected previously!
I hope this is clear...
Here is my code...
Thanks
''''''''''''''''''''''Problem - not reading the correct office when in edit mode Function GetSelectedIndex(ByVal PageID As String) As Integer
Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn")) Dim cmd As New SqlCommand("SelectOffice", Myconn) cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim myReader As SqlDataReader = cmd.ExecuteReader()
If myReader.HasRows Then Do While myReader.Read() Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1)) Loop Else Console.WriteLine("No rows returned.") End If myReader.Close()
Myconn.Close() End Function
Sub populateDDL_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
Dim pageID = CInt(CType(e.Item.FindControl("pageID"),
TextBox).Text) 'Construct the Database Connection Dim Myconn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn")) Dim cmd As New SqlCommand("SelectOffice", Myconn)
If e.Item.ItemType = ListItemType.EditItem Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names add_Office = CType(e.Item.FindControl("DDLeditOffice"), DropDownList) add_Office.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) add_Office.DataTextField = "offName" add_Office.DataValueField = "officeID" add_Office.DataBind() add_Office.SelectedIndex = GetSelectedIndex(pageID) Myconn.Close() Else
If e.Item.ItemType = ListItemType.Footer Then
cmd.CommandType = CommandType.StoredProcedure
Myconn.Open()
Dim add_Office As DropDownList
'Populates Office DropDownList with office names add_Office = CType(e.Item.FindControl("DDLaddOffice"), DropDownList) add_Office.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) add_Office.DataTextField = "offName" add_Office.DataValueField = "officeID" add_Office.DataBind() add_Office.Items.Insert(0, "Select One") add_Office.Items.FindByText("Select One").Value = 0
'insert don't create a value, but we need a value during defaults add_Office.SelectedIndex = 0 Myconn.Close() End If End If End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Faith |
last post by:
I found code on www.codeproject.com. Here is a sample it
is called DataGridColumnDropDown. I modified it to use
the text box when I wanted it to depended on a certain
search criteria.
Public...
|
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...
|
by: localhost |
last post by:
A DataGrid with shows a label in one of the columns when
in view mode. When in edit mode, I want to show a
dropdown, and have the default selection set to what the
textbox used to be. Right now...
|
by: NewToDotNet |
last post by:
Hi,
I am very new to ASP.NET and web programming in general. I have one issue. I have a Datagrid object with Edit template. In one Datagrid row, I have 1 DropdownList, 1 textbox and 1 readonly...
|
by: Vik |
last post by:
How can I display the lookup values in a datagrid?
E.g., the datagrid displays a table that contains a ProductID field. I want
to display a Product description from a Product table in that...
|
by: Dave |
last post by:
Hi,
I'm building a maintenance form for a table and some of the fields are
textboxes (i.e name) and some should be dropdowns (i.e country of origin)
When a user clicks 'Edit' in the...
|
by: Terry Olsen |
last post by:
I've got a datagrid set up to display data. I've also got an
Edit,Update,Cancel column set up to allow editing of data.
I've got a DropDownList (ID="ddl3")in the EditItemTemplate for a certain...
|
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...
|
by: bh |
last post by:
I'm trying to edit data in a datagrid through a dropdown list with different
id/text values. The problem comes in when I click the edit button & nothing
appears to be happening. Did I do...
|
by: pleaseexplaintome |
last post by:
Hi all,
I have a datagrid with a dropdownlist and would like to have the
dropdownlist display a database value correctly while the grid is in
edit mode.
I have a templatecolumn as follows:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |