Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding values to a column in a datagrid using the code behind.

Status
Not open for further replies.

stevet26

Programmer
Feb 9, 2005
53
Hi

I have an default.aspx page which calls in a user control containing a datagrid.

The datagrid has two columns, Name and Value. The name column is filled in automatically by the user controls code behind. The value filed is left empty because it needs to be populated by the default page.

The default page contains a couple of text fileds and a drop down box. Depending on what is seleteded in the drop down box determins whether the user control is called in or not.

If the user control is called in, I need to take a a comma separated string from the database, split it and loop through the rows in the datagrid adding a each split item to the datagrids value column.

Now i can find the datagrid fine how ever it is having a problem with the loop. Here is the code





Dim datTemplateFile As SqlDataReader
Dim strString As String
Dim arrArray() As String
Dim strItem As String
Dim icount As Integer
Dim urcHiddenPanel As Control = CType(plcContainer.FindControl("urcHiddenPanel"), Control)
Dim grdStoredProc As DataGrid = CType(urcHiddenPanel.FindControl("grdStoredProcParams"), DataGrid)

strString = datTemplateFile("TC_StoredProcParams")
arrArray = strString.Split(",")
icount = 0

For Each strItem In arrArray

grdStoredProc.Items(icount).Cells(1).Text = strItem

icount = icount + 1
Next





If anyone has experienced a problem like this before and solved it then any assistance would be much appreciated.

Thanking you in advance.
 
You say that you "can find the datagrid fine how ever it is having a problem with the loop". What "problem" is it having?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Line: grdStoredProc.Items(icount).Cells(1).Text = strItem

For loop is fine though.
 
For loop is fine though.
The For...Next loop obviously isn't fine as the index that you are using (icount) is out of range.

Try stepping through your code and see the what icount is when it produces the error - you'll then have to find out why that Item doesn't exist in the datagrid.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top