473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

Jul 21 '05 #1
0 1332

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

Similar topics

1
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
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
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
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
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...
0
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...
3
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
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
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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 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.