C# - How To Clear The GridView Column Greater Than Index 1
Jun 28, 2010how to clear the GridView column greater than index 1.
grdview.Columns.Clear() will clear all columns, but i need to clear the columns greater than index 1
how to clear the GridView column greater than index 1.
grdview.Columns.Clear() will clear all columns, but i need to clear the columns greater than index 1
I keep getting an error:Index (zero based) must be greater than or equal to zero and less than the size of the argument list.y code:
OdbcCommand cmd = new OdbcCommand("SELECT FirstName, SecondName, Aboutme FROM User WHERE UserID=1", cn);
OdbcDataReader reader = cmd.ExecuteReader();
while (reader.Read())
[code]...
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.
View 1 RepliesI have a gridview and the OnRowDataBound event is linked to this function:
if (e.Row.RowType == DataControlRowType.DataRow)
{
ThisRow = e.Row.DataItem as MyObjectModel;
if (ThisRow.Property1 == null) { e.Row.Cells[5].Text = "-"; }
This code looks at the value of a property of the object in the data source and if it's null, converts the null to display "-" in column 5. The problem I'm having is that if I change the order of the columns of the gridview, then I need to change the index of every other modification. What I'd like to do is change the statement "e.Row.Cells[5].Text" to something that says "the cell whose column header is xyz".
I am trying to write a small method to loop through and find a GridView Column by its Index, since it can change position based on what might be visible.
Here is what I have so far:
private int GetColumnIndexByName(GridView grid, string name)
{
foreach (DataColumn col in grid.Columns)
{
if (col.ColumnName.ToLower().Trim() == name.ToLower().Trim()) return col.Ordinal;
}........
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?
View 4 RepliesI 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
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 ?
View 5 RepliesI have a gridview control and in need to get the column name and the column index number
View 3 RepliesI am bindibg data to a grid and in my asp page I have the following asp:HyperLinkField:
asp:HyperLinkField
DataNavigateUrlFields="serialno"
DataTextField="serialno"
HeaderText="serialno" DataNavigateUrlFormatString="DeviceDetails.aspx?serialno={0}"
/>
This is working perfectly, but when I add a second parameter to the querystring it does not work anymore:
DataNavigateUrlFormatString="DeviceDetails.aspx?serialno={0}&id={1}"This
I get the following error during DataBind to a grid: [System.FormatException] = {"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."} What does this mean? Is {1} not a string or is it because of something else?
I have this code to create a pdf but its giving an errors saying table width must be grater than zero, and also on the generated pdf should show the items with the associated image, the items are in a gridview and each item has an image. Also a paging option i want to create to if paging is true it must generate the pdf with the actual gridview page else should create a pdf with all items and ignore which page are selected...
View 1 Replieshow to display result in gridview according to textbox only if textbox2 date value is greater than textbox1 ?
i have two textboxes and gridview ... if i type in Textbox1 : 2-Jan-2011 and in textbox2 : 1-Jan-2011 then in label1 the eroor message display else ..if textbox2 value is greater then textbox1 value then gridview will display records according to textbox1 and textbox2 from database ...
how to do that?
I am having difficulty with getting the values from two textboxes to passed the values to one function and determine that one textbox cannot be greater than the other textbox, then i can issue alert message.
For opener, i do not want onclick issue.
[code]....
Id name
1 xyz
2 pqr
5 mnp
3 iuy
4 lkj
in a sql table like this how to get the column index of a particular name like out put will be for "mnp" index is 3....(not according to id) what will be the sql query or if it is a datatable then what will be the code to find the column index...
I need to create the index for a column and accessing that in sqlserver 2005.
View 3 RepliesgvOff.DataSource = o.ViewData(dCity.SelectedValue);
gvOff.DataBind();
gvOff.Columns[0].HeaderText = "ZZZZZZZZ";
gvOff.Columns[1].HeaderText = "YYYYYYYY";
gvOff.Columns[2].HeaderText = "XXXXXXXX";
Header count is correct.
AutoGenerateColumns: Flase/True ( i tried both)
If i remove the gvOff.Columns[index].HeaderText portions, GridView works fine, but when i put the gvOff.Columns[0].HeaderText, i get the exceptional error.
, i couldn't solve it. If you need further info, inform me.
EDITED:
Hold on! I commented the HeaderText portion and tested
int i = gvOffer.Columns.Count;
I found count is 0 eventhough the columns print out with DataBind()... Why?
NOTE: AutoColumn in this case is set to true. I guess i will have to edit the column
names from DataTable.
i want row index & column header(index) of the selected cell of datagrdview, all colums are dynamic.
View 3 RepliesI have create user wizard control and i put validation control for all field but when i close user control that validators dint clear in firefox or but clear in IE
View 3 RepliesWhen I use code from this thread: [URL] (converted to VB.net), the result for lblStatus is always "nothing"?
It's not clear for me why you use "label", because the fieldtype I am searching for in the gridview, is boundfield.
how can i change column index of girdview ,
i have to show button at right hand side
I want to display gridview column heading when mouse over to the particular column in the gridview.I am working in VisualStudio 2005 with MS.Net2.0 framework.I don't want to use ajax.
View 4 RepliesI have a column in SQL Server 2008 called MapLocation which is stored as the geography data type. This column is used to store the location of a building in one table, and the location of landmarks in another table. I have to list all landmarks within 4 miles of a building.
I have a clustered primary key on an automatically generated int column in each table. I assume that I need to create a spatial index on the MapLocation column in the landmarks table. This I guess would aid finding all landmarks within 4 miles.
My problem is that I am not sure what settings to use for this spatial index. I have set the spatial index to have the following settings:
Cells per object: 16 Level 1: Medium Level 2: Medium Level 3: Medium Level 4: Medium Tessalation Scheme: Geography gridAre these the best settings? Am I doing the right thing?
[Code]....
Main Gridview[Code]....
How to Clear the gridview.
View 1 RepliesI have a gridview that has a radiobuttonlist ( YES/NO ) selections. but since you cant uncheck once selected, they are asking to add a clear option so that if they make a mistake they can clear it..
How can i do that within a gridview so that they can clear any mistakes prior to submission?
I have a loop checking all my radiobuttons to perform an update, so if i would like to be able to clear the selection as soon as the click on "Clear" so when they submit, that row shows as if it was never selected.