I have a gridview which is bound to a SQL data source. I have a series of controls used to filter the data. I notice that if I use the column property to hide a column which I do not want the user to view or edit my ROWDATABOUND event cannot refrerence
the column using row.cells(n).text. The problem is that I need to reference the hidden column so that I can use in backend code to filter the data.
Below is a basic example of what I am trying to do but wont work,
GridviewX (I hide column 1 using gridview property visibility=false (dont want user to see this code)
Code Color Planet
1234 blue earth
1235 red mars
4567 gray pluto
Visible gridview example below.
Color Planet
blue earth
red mars
gray pluto
Now in background code rowdatabound event I want to reference the code column so that I can filter some of the rows. I tried to use e.row.cells(0).text = ddl.selectedValue but my backend code cannot reference column0 which is used for code.
My question is is there another way to hide column0 code so that i can still reference the column in code behind rowdatabound event or is there another statement that can be used to check the column0 data or am I totally off and need some other options?
I am trying to do all this in background code. I cannot simpley buidl the gridview in background and must filter it on rowdatabound event because I have special format and cell controls like dropdownlist, radiobuttons etc in the cells to help the user and
apply contraints on the data that can be edited and updated using the gridview.
yes, I have the RowDataBound as you suggested. I see R1 and R7 only. Some rows I have visible=false set in GUI because I dont want user to see them and those rows I cannot see. Also I have rows 5 and 6 as bound ddl controls to help the user and they also
do not show. Baic code below I am setting all rows to a drop
All I am trying todo is have a gridview that can be filtered with controls to limit the gridrows for the user. I also need a wildcard (which I cannot seem to code) so that if the user does not use the control to select a value the default value will dislay
all the values for that control.
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
I like this gridview but there are so many quirks filtering the data that I am going nuts and cannot seem to get my needs.
I have no idea what todo now because I have spent so much time trying to resolve gridview issues to filter the data and cannot succeed.
The label is just for testing (just a page control to set all the data to see if it is accessible (visible) - not important.
Here is the problem better described.
e.g. my SQL data has 10 columns
col1....col10
I want to only show 5 columns (1,4,5,7,9)
I use the gv to hide the other 5 columns using visible paramter false. This works for the view fine. The pblm is that once this is done I cannot reference the hidden columns. once I have the 5 needed columns displayed i gv, I want to use backend rowdatabound
event (e.row.cells(x).text == somevar) to hide some of the rows. The rows would be hidden based on other input controls from the user.
Becasue of this I abandon the backend code rowdatabound event and try to do this using the GUI where clause bound to the user input controls and data binding (2 way) I tested this without the filters and the edit/update for the rows works perfect. I apply
the where filters and the the edit works but the update never does.
My feeling is that the backend code would be better to use but cannot get it to work as described above. I was thinking that I could bind the gv to all 10 columns and just hide them as needed. The basics of this works but then I have problems referenceing
the 5 hidden.
the other options was to use he gv where clause bound to the control this filter works perfect but cannot seem to get the edit/udpate to work.
So, if I cannot find the resolve for this gv issue, I wonder if it is possible for me to try this another way not tested above?
Also I was wondering if I may need to break this down into steps. meaning. setup the gv with user controls on page 1 to filter the GV rows but pass this to anoter page where the user can edit/update. At the moment everthing is on the same page. just use
panels hide and unhide as needed.
gogginl
Member
79 Points
261 Posts
Gridview Limitations filtering data
Nov 07, 2012 01:08 PM|LINK
I have a gridview which is bound to a SQL data source. I have a series of controls used to filter the data. I notice that if I use the column property to hide a column which I do not want the user to view or edit my ROWDATABOUND event cannot refrerence the column using row.cells(n).text. The problem is that I need to reference the hidden column so that I can use in backend code to filter the data.
Below is a basic example of what I am trying to do but wont work,
GridviewX (I hide column 1 using gridview property visibility=false (dont want user to see this code)
Code Color Planet
1234 blue earth
1235 red mars
4567 gray pluto
Visible gridview example below.
Color Planet
blue earth
red mars
gray pluto
Now in background code rowdatabound event I want to reference the code column so that I can filter some of the rows. I tried to use e.row.cells(0).text = ddl.selectedValue but my backend code cannot reference column0 which is used for code.
My question is is there another way to hide column0 code so that i can still reference the column in code behind rowdatabound event or is there another statement that can be used to check the column0 data or am I totally off and need some other options?
I am trying to do all this in background code. I cannot simpley buidl the gridview in background and must filter it on rowdatabound event because I have special format and cell controls like dropdownlist, radiobuttons etc in the cells to help the user and apply contraints on the data that can be edited and updated using the gridview.
Please any idea helpful.
oned_gk
All-Star
31810 Points
6505 Posts
Re: Gridview Limitations filtering data
Nov 08, 2012 12:30 AM|LINK
Make sure you referent e.row.cell(n).text in datarow only
If e.Row.RowType = DataControlRowType.DataRow Then 'your code here End IfFrank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: Gridview Limitations filtering data
Nov 09, 2012 05:51 AM|LINK
Hi,
You can cancel the first column and replace it with DataKeyNames property:
Then access the datakey
Also, you can set a TemplateField with HiddenField in the first column and bind the hiddnen field:
<asp:TemplateField> <ItemTemplate> <asp:HiddenField ID="HiddenField1" runat="server" value='<%#Eval("id") %>'/> </ItemTemplate> </asp:TemplateField>Access the hidden control in code behind.
Feedback to us
Develop and promote your apps in Windows Store
gogginl
Member
79 Points
261 Posts
Re: Gridview Limitations filtering data
Nov 09, 2012 05:15 PM|LINK
yes, I have the RowDataBound as you suggested. I see R1 and R7 only. Some rows I have visible=false set in GUI because I dont want user to see them and those rows I cannot see. Also I have rows 5 and 6 as bound ddl controls to help the user and they also do not show. Baic code below I am setting all rows to a drop
All I am trying todo is have a gridview that can be filtered with controls to limit the gridrows for the user. I also need a wildcard (which I cannot seem to code) so that if the user does not use the control to select a value the default value will dislay all the values for that control.
Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowType = DataControlRowType.DataRow Then
LabelDebug.Text = "R1=" + e.Row.Cells(1).Text + " R2=" + e.Row.Cells(2).Text + " R3=" + e.Row.Cells(3).Text + " R4=" + e.Row.Cells(4).Text + " R5=" + e.Row.Cells(5).Text + " R6=" + e.Row.Cells(6).Text + " R7=" + e.Row.Cells(7).Text + " R8=" + e.Row.Cells(8).Text + " R9=" + e.Row.Cells(9).Text + " R10=" + e.Row.Cells(10).Text + " R11=" + e.Row.Cells(11).Text + " R12=" + e.Row.Cells(12).Text + " R13=" + e.Row.Cells(13).Text + " R14=" + e.Row.Cells(14).Text
I like this gridview but there are so many quirks filtering the data that I am going nuts and cannot seem to get my needs.
I have no idea what todo now because I have spent so much time trying to resolve gridview issues to filter the data and cannot succeed.
oned_gk
All-Star
31810 Points
6505 Posts
Re: Gridview Limitations filtering data
Nov 10, 2012 01:13 AM|LINK
I m not sure understanding what you mean.
What is LabelDebug.Text? Where you place the control?
gogginl
Member
79 Points
261 Posts
Re: Gridview Limitations filtering data
Nov 12, 2012 01:01 PM|LINK
The label is just for testing (just a page control to set all the data to see if it is accessible (visible) - not important.
Here is the problem better described.
e.g. my SQL data has 10 columns
col1....col10
I want to only show 5 columns (1,4,5,7,9)
I use the gv to hide the other 5 columns using visible paramter false. This works for the view fine. The pblm is that once this is done I cannot reference the hidden columns. once I have the 5 needed columns displayed i gv, I want to use backend rowdatabound event (e.row.cells(x).text == somevar) to hide some of the rows. The rows would be hidden based on other input controls from the user.
Becasue of this I abandon the backend code rowdatabound event and try to do this using the GUI where clause bound to the user input controls and data binding (2 way) I tested this without the filters and the edit/update for the rows works perfect. I apply the where filters and the the edit works but the update never does.
My feeling is that the backend code would be better to use but cannot get it to work as described above. I was thinking that I could bind the gv to all 10 columns and just hide them as needed. The basics of this works but then I have problems referenceing the 5 hidden.
the other options was to use he gv where clause bound to the control this filter works perfect but cannot seem to get the edit/udpate to work.
So, if I cannot find the resolve for this gv issue, I wonder if it is possible for me to try this another way not tested above?
Also I was wondering if I may need to break this down into steps. meaning. setup the gv with user controls on page 1 to filter the GV rows but pass this to anoter page where the user can edit/update. At the moment everthing is on the same page. just use panels hide and unhide as needed.
gogginl
Member
79 Points
261 Posts
Re: Gridview Limitations filtering data
Nov 27, 2012 04:30 PM|LINK
This was resolved by editing the ASPX file and modifying the update satatment and select satatment manually.