Forms Data Controls :: Hiding A Column In Gridview - Index Out Of Range?
Jul 27, 2010
I have been trying to hide a column but make use of the value in another function but the function i am trying to hide it give me and error at the embolded line. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Public Sub FetchDetails()
Dim valtable As DataTable = New DataTable()
valtable.Columns.Add("LINK")
valtable.Columns.Add("WATCH PERIOD")
valtable.Columns.Add("DAY ENTRY")
valtable.Columns.Add("listid")
Dim seltext As String = "SELECT [Watchlistname], [Watchlisturl], [Watchlistdate],[listid] FROM [Watchlist]"
Dim madap As SqlDataAdapter = New SqlDataAdapter(seltext, Connection())
Dim mdset As DataSet = New DataSet()
Dim i As Integer = 0, pager As Integer = 0
madap.Fill(mdset, "WATCHLIST")
Session("tab") = mdset.Tables("WATCHLIST")
For Each arow As DataRow In Session("tab").Rows
Dim valrow As DataRow = valtable.NewRow()
valrow("LINK") = arow("Watchlisturl")
valrow("WATCH PERIOD") = arow("Watchlistname")
valrow("DAY ENTRY") = arow("Watchlistdate")
valrow("listid") = arow("listid")
valtable.Rows.Add(valrow)
Next
'Dim str As String = ChrW(8358)
gridWatchlist.DataSource = valtable
gridWatchlist.DataBind()
gridWatchlist.HeaderRow.Cells(1).Visible = False
gridWatchlist.HeaderRow.Cells(2).Text = "WATCH PERIOD"
gridWatchlist.HeaderRow.Cells(3).Text = "DAY ENTRY"
gridWatchlist.Columns(4).Visible = False
End Sub
it is a simple question, but i didn't understand. here is the code below:
Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated Dim drv As DataRowView If e.Row.RowType = DataControlRowType.DataRow Then For i As Integer = 0 To e.Row().Cells.Count If " ".Equals(e.Row().Cells(i).Text) Then e.Row().Cells(i).Text = "" End If Next End If End Sub
the line "If e.Row.RowType = DataControlRowType.DataRow Then" occured exception below System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection
I am getting error Specified index out of range of valid values. Parameter name index. I tried to put a breakpoint and see where am I getting the error. I have 5 columns (1 hidden). first 3 columns- no issue. But when the control reaches the 4th column it throws the error. I saw that I am getting correct values for the first 3..no ide what is going wrong with the 4th one.
I have used the DataKeyNames property of the GridView to assign the column name whose visible property is set to false to get the cells value when the column is kept invisible. But, sometimes there is an error on this line of code - string cellValue = GridView.DataKeys[e.NewEditIndex].Value.ToString(); Following Error is generated -
Server Error in '/' Application. Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
i use objectdatasource control for bind record and also in gridview paging.in my gridview there is a linkbutton(edit) when i click it then it redirect to next page with some key value.but problem is when i try to paging in gridview an error is occure that is Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
I have used to code below successfully to export a gridview to an excel spreadsheet, however when i use it for a gridview with data from a different table i receive the following error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The thing is it works locally fine but when i upload to my shared server i receive the error above?
I am having some trouble hiding a column in my GridView. For some reason when I do the following:
[Code]....
It hides the column correctly but also leaves an empty gray column at the end of my grid which is about 5px. Ideally I don't want to remove the column but hide it, but if I do remove it is it possible to remove the binded that column represents?
what I would like to do is to only show the AuthorFirstName and AuthorLastName columns for the first row of each author. I am easily doing this with:
[Code]....
However the issue that I'm seeing now is the formatting what happens is that after the first row that the Author names are hidden but then the BookTitle and YearPublished become the new cell(0) and cell(1) respectively which means that book and year are displaying underneath the author names columns. so my goal is to do 2 things:
1 have BookTitle and YearPublished render under the correct headers and
2. For the second row and after I would like the cell to appear the same as the background, I dont want the user to be seeing what looks like an empty cell or textbox there.
somehow I broke this b/c it was working... I've got a gridview with a standard delete button. here is the top of the gridview:
[Code]....
and here is the SQL source:
[Code]....
here is my rowdeleting event:
[Code]....
the error: Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index happens after that on line 31 of ss.gv_NotificationDetails
[Code]....
interestingly if I add more columns to the datakeynames, the error moves up one line to e.Values(0unfortunately I do not remember everything I have changed since the last time I tested this.
I have a grid view with 4 columns and 12 rows. Getting the row index is not problem; ;however, I cannot find a way to get the column index of the cell that i select.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Is there a way to find out which column is selected in the Gridview row command? When I click on a gridview row in a specific column, is there a way to get the column index of the selected row?
I recently had to remove a field from my datakey on all three gridview tables. On the top level table the field (ignum) remains as a non key field. On the two lower level tables it was removed completely. Now, the top level gridview opens correctly, but when I click on select this should bring up all the records in the second gridview associated with the selected row in the first gridview, but I get the following error:
[Code]....
I've looked at everything I can thing of and everything looks ok. The tables look good, I've removed all references to the removed field and I've restructured all the code to account for the changes. I'm missing something, but I don't know what. I've gone through debug step by step and the error occurs as I leave the GridView1_SelectedIndexChanged code. It goes down to the End Sub line with no errors, but when I step again it errors out. Here is that section of code.
using above code i am able to print gridview directly without hidden fields.after added to hiddenfields to gridview , hiddenfield values are visible for printing.after i am using gridview.colums[i].visible=false column not visible while printingproblem is after print the gridview not visible whatever my columns set visible false.Example:at printing time i am set checkbox visible false, after printing i want reload same page with checkbox but check box not visible after printing gridview
i know how to find the index of selected row in asp gridview , but i need to find the index of selected column in asp gridview ?for ex:i have i gridview contains columns with header ( the header is the primary key i looking for ) , this grid contain linkbutton , i want to get the column header name on click on linkbutton ?
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
Line 61: Dim favorname As String = GridView1.DataKeys(row.RowIndex).ToStringLine 62: Line 63: ' Pass the value of the selected Employye ID to the Delete //command. My coding as Protected Sub btnMultipleRowDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMultipleRowDelete.Click ' Looping through all the rows in the GridView For Each row As GridViewRow In GridView1.Rows Dim checkbox As CheckBox = CType(row.FindControl("cbRows"), CheckBox) 'Check if the checkbox is checked. 'value in the HtmlInputCheckBox's Value property is set as the //value of the delete command's parameter. If checkbox.Checked Then ' Retreive the Favorname Dim favorname As String = GridView1.DataKeys(row.RowIndex).ToString ' Pass the value of the selected Employye ID to the Delete //command. SqlDataSource1.DeleteParameters("Favorname").DefaultValue = favorname.ToString() SqlDataSource1.Delete() End If Next row End Sub <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="563px" AutoGenerateColumns="False"> <RowStyle CssClass="fontsmallthennormal" /> <HeaderStyle CssClass="fontnormalblue8" /> <EditRowStyle CssClass="fontsmallthennormal" /> <Columns> <asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="cbRows" runat="server"/> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Favorname" HeaderText="Favorname" SortExpression="Favorname" /> <asp:BoundField DataField="FavorDate" HeaderText="FavorDate" SortExpression="FavorDate" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:yyyy %>" runat="server" SelectCommand="SELECT [US], [Favorname], [FavorDate] FROM [TBL_FAVORITES] WHERE ([US] = @US)" DeleteCommand="DELETE from TBL_FAVORITES where [Favorname]= @Favorname" > <SelectParameters > <asp:ControlParameter ControlID="txtusername1" Name="US" PropertyName="Text" Type="String" /> </SelectParameters> <DeleteParameters> <asp:Parameter Name="Favorname" /> </DeleteParameters> </asp:SqlDataSource>
This is my first attempt at paging on a listview. The first time my page loads it loads the listview fine, but when I try to use the paging I get the following error:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Here's my code:
[code].....
When I take the following line out I don't get the error, but i need it to populate my controls: