 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 2nd, 2005, 02:44 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
When I use the aove method in the ItemCommand's Edit mode, I get a an exception saying Object Reference Not set to the instance of an object, as I see the dropDownlist is not getting recognised as an item in the datagrid, I have my dropdown in the editItemTemplate and in the ItemCommands Edit Mode I instantiated the dropdown as........
Dim ddRecvComments as DropDownList = e.item.Cells(7).FindControl("ddRecvComments"),
Then I placed the Code for populating DropDown In the "If e.Item.ItemType = ListItemType.EditItem" condition and found that the execution of code is surpassing the condition.
How can the DropDown in the editItemTemplate be instantiated..
Thanks!
|
|

August 5th, 2005, 06:21 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok, I got this one fixed, the problem being a Null value in the database table used to populate the DropDown.
Now, I want to add a new row with an empty string in the dropdownlist through the code, how can this be done.
Below is the LoadDropDown method, I am able to add the new row to the Dropdown from here, but again the same problem arises here. with this new added value the dropdown is again resetting to the default original value.
Public Sub LoadDropDownList()
'Dim drv As DataRowView
Dim ds_DropDownList = New DataSet
Dim da As SqlDataAdapter
Dim conn As SqlConnection = clsConnection.GetConnection()
Dim cmd As SqlCommand = New SqlCommand("Select * from t_ReceivingComments", conn)
da = New SqlDataAdapter(cmd)
da.Fill(ds_DropDownList, "t_ReceivingComments")
Dim y As Int32 = ds_DropDownList.Tables("t_ReceivingComments").Rows .Count
Session.Add("ds_DropDownList", ds_DropDownList)
TempDataView = New DataView(ds_DropDownList.Tables("t_ReceivingCommen ts"))
drv = TempDataView.AddNew
drv("ReceivingComments") = ""
End Sub
Is there any way I can add an empty string to the dropdown and make it as the default selected value after the data has been loaded in the dropdown.
Thanks!
|
|

August 6th, 2005, 12:12 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Try this:
ddRecvComments.Items.Insert(0, "")
ddRecvComments.SelectedIndex = 0
|
|

August 6th, 2005, 12:57 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Jim,
Thanks for the response. But I get an error Object Referece Not Set to the Instance of an object when I try to add values to the dropdown list. The only places on the Code Behind where I am able to access the DropDown List are in the edit command, Save or the selected index changed event of the dropdown list.
Even when the CommandName = Edit, I am not able to instantiate the dropdown list.
Any clues on how to do this?
Thanks A lot again for your patience and response.
Thanks
|
|

August 6th, 2005, 01:01 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Try putting the code in the datagrid's ItemDataBound event.
|
|

August 6th, 2005, 02:02 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Jim,
I am able to add an empty sting to the dropdown in the ItemDdataBound and again the DropDown is Resetting, can you suggest any other work around for this....
Adding any thing to the List at run time is causing it to reset, I even added a string and tested, the dropdown is again defaulting to the SelectedIndex = 0.
Thanks again..........
|
|

August 6th, 2005, 11:21 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
In my code I specified it to set to index 0, as you asked, You said you want a blank, as the first item and have it selected. I am not understanding the problem.
|
|

August 7th, 2005, 11:06 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
The code i gave you always sets the index to 0 as you wanted.
|
|

August 12th, 2005, 12:37 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Jim,
Thanks for all your response, I did not have problems with your code through your code I was able to add an empty string to the drop down and make it the default selected value.
The actual problem I was facing was the alues in the dropdown were getting reset and pointing to the default selected value event another value was selected. This problem was ocuuring because of the file (scroll.htc from MSDN) I was using to add a scroll bar to datagrid. once i removed this file from the project I the problem vanished.
Thanks I learned some valueable tips from you.
Thanks again...... :)
|
|

August 12th, 2005, 12:49 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Glad you got it fixed and glad i could help. If you want a scrolll bar next to your datagrid, place the datagrid insided of a <DIV> </DIV> tag. then set the height value of the div to less than the height of the grid and set autoscroll to true. I do this for my datagrid and works well.
|
|
 |