473,503 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Datagrid Problems

Hello

I have hit a major road block when it comes to building my dynamic datagrid. To make a long story short I need a dynamic datagrid because my connection string could change and I need the datagrid to handle that. First I tried to create my datagrid by leaving the auto-generate columns equal to true. This worked fine except that when my user wants to edit a line I do not want them to edit column 1, only column 2. I could not find a way to set this. For this reason I moved to programically creating the whole datagrid. This way I could control the read-only attribute of each cell. However, I am having difficults when it comes time for me to grab the values out of the datagrid for an update. For some reason I am getting a "Specified argument was out of the range of valid values. Parameter name: index" error. Could you please review the below code and explain to me what it is I am doing wrong

************************************************** *******************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateColumns()
If Not Page.IsPostBack Then
BindDataGrid()
End If
End Sub

Private Sub CreateColumns()
dgProductLocation.AutoGenerateColumns = False
' Add two columns to the datagrid that only has an edit column in it
Dim dgcPhysLocID As New BoundColumn
dgcPhysLocID.DataField = "ProductLocID"
dgcPhysLocID.HeaderText = "ID"
dgcPhysLocID.ItemStyle.Width = New Unit(120)
dgcPhysLocID.ReadOnly = True
dgProductLocation.Columns.Add(dgcPhysLocID)
Dim dgcDescription As New BoundColumn
dgcDescription.DataField = "ProductLocationDesc"
dgcDescription.HeaderText = "Description"
dgcDescription.ItemStyle.Width = New Unit(120)
dgcDescription.ReadOnly = False
dgProductLocation.Columns.Add(dgcDescription)
End Sub

Private Sub BindDataGrid()
'Creates the dataset that will populate the datagrid
Dim dsPhysLoc As DataSet = ExecuteDataset(ConfigurationSettings.AppSettings.I tem("sConn"), "GetFBHICSPhysicalLocations", ConfigurationSettings.AppSettings.Item("LocationID "))
dgProductLocation.DataSource = dsPhysLoc
dgProductLocation.DataBind()
End Sub

Private Sub dgProductLocation_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgProductLocation.UpdateCommand
'Local Variable Declarations
Dim strLocID, strProdLocID, strProdLocDesc As String
Dim sCmd As New System.Data.SqlClient.SqlCommand
'Get and Holds the Value From the DataGrid Item
***
THIS IS WHERE I GET THE ERRO
***
strProdLocID = e.Item.Cells(1).Text
strProdLocDesc = CType(e.Item.Cells(2).Controls(0), TextBox).Text
'...More Code...
End Sub
************************************************** *********************************

I would appreciate any help with this as I am at a brick wall right now. Also....once I get past this I will need to know how to convert the second column to a drop down list instead of a textbox in edit mode. It's funny how all of this was so easy with the property builder before I had to start making it dynamic

Thanks In Advance for All Your Hel
Je

Nov 22 '05 #1
0 1271

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

Similar topics

0
1341
by: JP011 | last post by:
Hello I have hit a major road block when it comes to building my dynamic datagrid. To make a long story short I need a dynamic datagrid because my connection string could change and I need the...
1
2052
by: Mark | last post by:
Hello, I have a database which contains approximately 30 reference tables. I've been looking at building a dynamic datagrid that is updateable, but have run into problems with the Cancel and...
1
1576
by: Karine Proot | last post by:
Hello Today I had to build a DataGrid very dynamically <asp:datagrid id="dgTAB" Runat="server" AutoGenerateColumns="False" OnEditCommand="TAB_Edit" OnCancelCommand="TAB_Cancel"...
0
1683
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
4
1679
by: Diego F. | last post by:
Is it possible to generate dynamic reports with Crystal? I'm having problems printing a datagrid because the last line of each page gets cut, so I was thinking of using Crystal. I want to simply...
8
2001
by: George Meng | last post by:
I got a tough question: The backgroud for this question is: I want to design an application works like a engine. After release, we can still customize a form by adding a button, and source code...
3
13724
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
3
1423
by: Bart Van Hemelen | last post by:
Here's what I'm trying to accomplish: I get a number from another page that indicates the number of members. The page I want to build -- actually it's not a page, but a UserControl -- needs to...
0
2895
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...
2
2686
by: WolfyUK | last post by:
Hello, I have a standard asp:DataGrid called CasesGrid that I wish to write my own paging controls for. The aim is to get something like the following rendered to screen: << First < Previous...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
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
7271
Oralloy
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,...
0
7319
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...
1
6979
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...
0
5570
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
4998
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
4666
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
3160
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...

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.