Getting the value of a control in gridview_rowcommand event

I have this gridview control with a linkbutton control. the index of the / datakey of the records/data bind to the gridview is a string. I assign each index to the commandargument of the control and eventname as "play", I also have another control i assign a value called "hiddenfield", all in the templatecolumn, all I want to achieve is that whenever I click on the button from the gridview_rowcommand event, I want to be able to get the value of the control - hiddenfield at anytime i clicked the biutton.

This is my html code

<asp:GridView ID="GVVideos" AutoGenerateColumns="false" AllowPaging="false"  runat="server" CellPadding="2" CellSpacing="2" AlternatingRowStyle-BackColor="aliceblue" GridLines="None">
    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
    <img alt="<%# Eval("title") %>" src="<%# Eval("thumbnailUrl") %>" />
    <asp:LinkButton ID="lBtnTitle" runat="server" Text='<%#Eval("title") %>' CausesValidation="false" CommandName="play" CommandArgument='<%#Eval("id") %>' /><p></p>
        <asp:Label ID="lbDesc" Font-Size="8pt" ForeColor="black" runat="server" Text='<%#Eval("description") %>'></asp:Label><br />
       <asp:Label ID="Label1" runat="server" Text="Views: " /><asp:Label ID="lbTitle" runat="server" Text='<%#Eval("viewCount") %>' />&nbsp&nbsp
         <asp:Label ID="Label7" runat="server" Text="Rating: " /><asp:Label ID="lbRating" runat="server" Text='<%#Eval("ratingavg") %>' />
         <asp:Literal ID="lId" Visible="false" Text='<%#Eval("ID") %>' runat="server" />
         <asp:Literal ID="lEmbed" Visible="false" Text='<%#Eval("Embed_Status") %>' runat="server" />
         <asp:HiddenField ID="hfPictureUrl" runat='server' Value='<%#Eval("thumbnailUrl") %>' />
        <AlternatingRowStyle BackColor="AliceBlue" />

and from code behind

Protected Sub GVVideos_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GVVideos.RowCommand
        If e.CommandName.ToLower.Equals("play") Then

            //this is the index of the data but it's a string and not an integer
            Dim videoId As String = e.CommandArgument.ToString
            Dim pictureUrl As HiddenField = CType(GVVideos.SelectedRow.FindControl("hfPictureUrl"), HiddenField)

        End If
    End Sub


when i try this, this throw an error. PLease, can anyone help me out as in what to do to get the value of control.

Any idea is welcome 

Kayode Banjo

Technology Specialist 

11/14/2007 6:20:29 PM 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 14

 It's not a selected row.  Make the CommandName="Select"


then change: If e.CommandName.ToLower.Equals("select") Then 

If this post helped you, Mark As Answer.
11/14/2007 6:40:06 PM

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: 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....

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...

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...

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 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,,MC...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

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 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...

Datagrid(.net 1.1) to GridView(.net 2.0) and using the RowUpdating event how to extract the values from the controls.
Ok  This is the settings: I use a Viewgrid with only itemtemplate colums for example. <asp:TemplateField HeaderText="Test"><ItemTemplate><asp:Label id="LBL_Test" text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' runat="server" meta:resourcekey="LBL_TestResource1"></asp:Label></font></ItemTemplate> <EditItemTemplate><asp:TextBox ID="HDN_Test" Text='<%# DataBinder.Eval(Container.DataItem, "Test1") %>' Runat="server" meta:resourcekey="HDN_TestResource1" /></EditItemTemplate></asp:TemplateField>  The ...

Getting Information from the Controls (TemplateField or BoundField ) from any of the Data Presentation Controls
Hello Everybody,I have a very important question for me.For example, I have a GridView.It has three BoundFields and one TemplateFieldI want to get information from any of the record (row,line etc ) using any of the BoundFields or TemplateFields.And also I want to accomplish this not only with GridView but also other Data Presentation Controls, DetailsView FormView and Repeater.Shortly, Can anybody help me how to refer Controls in GridView, FormView, DetailsView, RepeaterPS: I have searched in Google and many sites,forums. But I couldn't see any solution and see that many people ask the same ...

Run an event whose control is located in Data Presentation Controls
Hey, How can we fire an event which belongs to such as a button which is located in Data Presentation Controls such as a gridview.For example : Assume that my page contains a gridview control which is contains a button and the button name comes from database by gridview control but i wanna fire button control's own event independently of the GridView. Thanks and Regards.I am not a perfect programmer, but i have perfect programmers' habits [ i think so :)] Hi:   You can use CommandArgument to distinguish different buttons in the same column: <asp:Button ID="Button2&...

LITERAL control containing html SELECT control
on a web page written in VB.NET , I have a literal control created. It's contents is : Literal1.Text = " <select name=""addselect"" id =""addselect"" style=""width=100%"" size=""2"" maxlength=""27"" runat=server " & _ " onclick=""__doPostBack(" & _ "'addselect','')"" " & _ " language= ""javascript""> " & _ " <optgroup label="&quo...

Getting value of a property in Parent User control from a Child user control
I have a ChildUserControl that is loaded inside a ParentUserControl. The host page loads ParentUserControl.I would need to access properties in ParentUserControl from the ChildUserControl.Thanks for your time Here's some ideas: You can from the child access the parent and run findcontrol. child.parent.findcontroL("indyanguy1") child.parent.parent.findcontrol("indyanguy1") The trick is when you get your findcontrol working to cast the result to the object type your looking forHere I'm looking for a label so I cast to label then I can use the .Text property.Y...

Dynamically Loading User Control and Maintaining its viewstate. And Getting Values from the control.
 I have a drop down which is populated on the page looad.  When i select an item from drop downlist i get to see two listboxes with add/removing the objects from one left to right listbox and below that i have a user control which should be populated dynamically based on the selectedvalue from drop down list.  So there are three sections that are seen once a selected value is consiedered from drop down list.  Now I am getting the user control using the below code givencase "42": viewRequired = "vw_AncCostSavingsByCarrier_adhoc";    ...

Get the values of dynamic controls during PageLoad event
Is there a way to get the values (checked/unchecked, text, properties, etc) of controls that are dynamically generated during each Postback? During PageLoad when I add the controls I need to be able to make decisions based on those values (the postbacks are coming through calling __doPostBack() on the client side in many cases, so I can't just do the work in a form submission event).Is there a way to get at those values? I keep seeing stuff about Viewstate, but it's all very vague about how to do something like this. Thanks to anyone who can help me out,     ...

Web resources about - Getting the value of a control in gridview_rowcommand event -

Resources last updated: 1/9/2016 4:32:12 AM