Get Value from Hidden Column in Gridview control

I have managed to get the value from my hidden field by using the SelectedIndexChanged event and the following line of code:

string keyValue = GridView1.SelectedDataKey.Value.ToString()

I would however prefer to get access to the hidden column value on the GridView1_RowDataBound event, so that I can then evaluate each row against the hidden columns value and decide whether or not to display the edit button in each row. Can I do this a different way?
0
LeMerovingian
10/5/2006 4:16:16 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
833 Views

Similar Articles

[PageSpeed] 50

You can use e.Row.DataItem("field name") in the RowDataBound event -  as long as the field is in your SQL statement doesn't matter whether it is in your Gridview as a hidden column or not.

Tim

0
cashmore
10/5/2006 10:24:24 PM
You can also use script in your GridView.
For example: if the field is a bit:
Visible='<%# Bind ("fieldnametobind") %>'
or when the field isn't null:
Visible=''<%# !Convert.IsDBNull(Eval("fieldnametoevaluate")) %>'
0
SilverSwan
10/5/2006 10:41:33 PM
Tim can you please elaborate more? Perhaps a sample? I have experimented with this but still no joy
0
LeMerovingian
10/6/2006 5:28:49 PM

A bit of code that might help. Also if I need to manipulate edit/update/cancel I usually use template fields rather than command field.

Tim

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

If e.Row.RowType = DataControlRowType.DataRow Then 'Check Row is data and not header/footer

If e.Row.DataItem("column name from sql").ToString = "" Then

Dim lb As LinkButton = e.Row.FindControl("cmdEdit") 'If column is null disable edit button

lb.Enabled = False

End If

End If

End Sub

0
cashmore
10/6/2006 6:51:20 PM

Hi Tim,

that worked well. I just had to convert it to c# (with a bit of casting).

Thanks for your help.
 

0
LeMerovingian
10/7/2006 6:11:56 AM
sorry i forgot to paste my code. here is the solution in case anybody needs to do it in c#

 
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (((DataRowView)e.Row.DataItem).Row["Role"].ToString() == "basic_user")
            {
                LinkButton b = (LinkButton)e.Row.FindControl("lbEdit");
                b.Visible = false;
            }
        }
 
0
LeMerovingian
10/7/2006 6:53:42 AM
Reply:

Similar Artilces:

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

Getting column value from a gridview control
I have a grid view control and has one datakey and other columns. In my grid view I have an Edit Control and a Delete Control. 1) When I press Edit control, I am getting datakey value as expected. But I am not getting other column name i.e. pdf_filename 2) when I press Delete control, I should get the datakey value. But I am not getting I am using c#  Please help me Hi vmk, Could you be a littlemore elaborate? like how have you bound your grid? 1.Columns autogenerated 2.Using TemplateFields 3.Using BoundFields.Regards,NaveenPlease remember to click Mark as Answer on the pos...

How to get the value hidden control of user control in .aspx page
How to get the value hidden control of user control in .aspx page   Thanks srinivas  If its a server control (runat attribute = server) and its markup starts with <asp:HiddenField ID="HiddenField1">, you can just call HiddenField1.Value to get the value stored in it. Even if your hidden field is not a standard asp.net control you can still retrieve the value provided the runat attribute is set to server.Hope this helps programming blog Use <%=testhid.ClientId%>For example getting a reference to the object would look like:var testid = document...

Issue with getting values from child controls in a gridview, to use for the update using a SQLDataSource control
Hi all, I have a gridview bound with a SQLDataSource. I am using the Update feature of the SQLDataSource to update a SQL Server database with values entered into the gridview. However I am not getting it to work. I believe this is due to the controls that contain the user entries are not the gridview itself, but rather child controls within the gridview. I have been using the names of the actual controls but nothing happens. Upon submit, the screen returns blank, and the database is not updated. Here is some code:   <asp:GridView ID="GridEditSettlement" runat="server" AutoGenerate...

GridView child of GridView
I have a Parent GridView and when you click in the Edit one of the columns has a Template Field which has a Child GridView. When you click Edit on the Child GridView I have a Template Field that has a TextBox. How to I retreive this value of the TextBox? GridViewParent-- GridViewChild (Edit - Template Field containing this GridViewChild)----- TextBox inside Template Field in GridViewChild. Thank you.Peace in ChristMarco Napolihttp://www.ourlovingmother.org What you can do as a solution is to override the RowDataBound and try to find the child GridView control. Once you get a reference to...

How can I control the width of a column in the GridView control.
From searching I see mention of ways to do it before the controls are bound. Is there a simpler way? If not, could someone explain to me how I need to go about it?Here is the code: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"        DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."        OnSelectedIndexChanged="GridView1_SelectedIndexChanged">   &nbs...

Panel Control is hidden by gridview control on same page
Hi, On one web page (.NET 2005) I have a panel control with many controls on it, in order to hide/unhide them. Below the panel I have a gridview control. When I browse the form, gridview overlaps panel control an hides it's controls. Can I stop this and have the panel first and gridview as a second control (not hiding panel) ? Thanks a lot in advance!  hi ChrisDev,   Try to add that panel and gridview in separate div tag. I think it will work for you.If not place in table's separate tr/td tag.Regards,Jags   ...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

obtaining the value of a dropdown control inside a gridview control
Hi, I am working on a site to process assessments against a particular business service. The assessments have 8 stages and there are questions for each stage with a list of responses. I am experimenting with different user interfaces for doing this and am open for suggestions on the best way, but for the moment I have a page for each assessment with a dropdown list containing stage 1-8, on selecting a stage a gridview is built containing the questions and responses for that particular stage. So the first column is the question and the second column a drop down list of possible responses, o...

Hidden Control does not update with new value but label Control does
Okay, this is an odd problem and I do not understand what is going on here. I have the following code contained within a loop.  I have removed alot of code that I feel is irrelivant but no where else within the loop do I modify hidInsCoID or lblInsCoId:for (int i = 0; i < ds.Tables[0].Rows.Count; i++) {HiddenField hidInsCoID = new HiddenField();hidInsCoID.ID = "hidInsCoID_" + i; hidInsCoID.Value = strInsCoID; Label lblInsCoId = new Label();lblInsCoId.Text = "<font name='verdana' color='" + strFontColor + "'><small><b>&q...

How get value from a dynamically created control in a user control
HI, I am working with a version of IBuySpy. On one page is a form that contains a user control that lists the items the user purchased, the subtotal, shipping, etc. I wanted to add a DropDownList from which the user could select the shipper. The dropdown list works fine as long as it has .AutoPostBack = false. However, I cannot figure out how to get the value that the user selected when they finally press the submit button on the form. All attempts to locate the control and it's value have failed. I tried drillingdown from the form to the child controls, and sub child controls. N...

Help getting control name and value of dynamic controls
I have an application which creates a dynamic form consisting of an html table with web controls in the page. I need a user to be able to fill in this form and then grab the values of each control and save both the control name and the control value to a database. This is the Code that I have Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If not ispostback then Dim infotable As New Table Dim objparticipant As New Participants.ParticipantInfo Dim objCustomFields As New CustomFieldController Dim TypeId As Intege...

Web resources about - Get Value from Hidden Column in Gridview control - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/11/2016 10:46:33 AM