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