Get Value From A DropDownList Template Field In Gridview - VB

Im just trying to call a value from a dropdownlist on a particular line in a gridview..


 Ive tried this code, I know it must be simple... just cant figure it out..

Protected Sub gvProducts_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvProducts.RowCommand

Dim SelectedRow As GridViewRow

Dim intQuantity As Integer

SelectedRow = Me.gvProducts.SelectedRow

'Message.Text = "You selected " & row.Cells(2).Text & "."

intQuantity = SelectedRow.Cells(3).Text 'fetches the quantity value from the current row.

lblTest.Text = intQuantity

End Sub


11/8/2006 4:33:56 AM 72751 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 42


dim tempDDL as DropDownList


//do something with tempDDL.SelectedValue

Best Regards,
Rex Lin
Microsoft Online Community Support

This posting is provided "AS IS" with on warranties, and confers no rights.
11/8/2006 5:54:20 AM

appreciate the help rexlin.. but im blue lining.. under 'SelectedRow'   ("Name SelectedRow is not declared")

im pretty sure I tried something similar to your code, but ran into the same problems, hence why I tried to declare the selectedvalue..




11/8/2006 6:17:08 AM


First,you can add the RowIndex Into the CommandArgument of Button. 

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        if (e.Row.RowType ==DataControlRowType.DataRow)
            Button myButton = (Button)e.Row.Cells[1].Controls[0];
            myButton.CommandArgument = e.Row.RowIndex.ToString();

Second, you can retrive the rowindex in the RowCommand. Let's say, you can get the certian selectedRow by the rowindex. 

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        if (e.CommandName == "confirm")
            int index = Convert.ToInt32(e.CommandArgument);
            HyperLink myLink = (HyperLink)GridView1.Rows[index].Cells[0].Controls[0];


Best Regards,
Rex Lin
Microsoft Online Community Support

This posting is provided "AS IS" with on warranties, and confers no rights.
11/8/2006 6:47:53 AM

Similar Artilces:

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 Napoli 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 to get cell values when GridView is bound with Template Control Fields
Hi, I have following GridView <asp:GridView ID="gdvProcAdmin" runat="server" AutoGenerateColumns="false" AllowSorting="true"> <Columns> <asp:TemplateField HeaderText="ID" Visible="false"> <ItemTemplate> <asp:Label ID="lblID" runat="server" Text='<%#Eval("ID")%>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Category" SortExpression="Type"> <ItemTemplate> <asp:Lab...

How to add values to template control fields textbox control in GridView..
Hi all,    <asp:GridView ID="GridView1" EnableViewState="true" DataKeyNames="LicenseTemplateID"                       runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"                       Width="345px">                       <Columns>                           <asp:Templa...

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

getting the value of a template field in a gridview
I have a gridview and one of my columes is a template field and the item template is a textbox.  I want to be able to pull the text of that text box out and store it in a string when the user hits a button on the field  I know the below code works when i am working with a field that is not a template and i am editing the row  i is the integer of the row i am working dim x as new textbox x = gv1.rows(i).cells(3).controls(1) dim a as string = x.text   So the above code works for me when I need to edit a cell in a gridview but now i dont want to edit anything.&nb...

Get value from template field on GridView
 I am trying to retrieve the value of a template field, here's the code I used to bind the data  <asp:TemplateField HeaderText="End Date"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("End_date", "{0: MM/dd/yyyy}") %>' Width="90px"></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("End_date&q...

get edit template control value in Gridview
 I have a gridview that has two edit item templates which have controls textbox and a label I want to get the value of the controls when I update the gridview and add that to the update parameters. I keep getting object reference not set to an instance of an object for the label and the textbox. I cannot figure this out.I can't believe this has stumped me as I know I have done it before and it is very simple I must be over looking something. here is my vb here is my vb Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewU...

how to get value selected from template field in gridview
Dear all       i am using asp.net2.0, C# and sql2005.  I was trying gridview using  templatefield to customize gridview.  My question is how to get selected dropdownlist item value that is used in gridview templatefield..say suppose gridview template populate countries and how to get programtically value of selected country.    hi friend.,try out this one..                         Dim cmbApp As New DropDownList     &nbs...

Getting the value of a template checkbox field from within a Gridview
I have generated a gridview thus: <asp:GridView ID="gridBatches" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlGetBatchNos" DataKeyNames="IssueThis"> <Columns> <asp:BoundField DataField="batch" HeaderText="batch" InsertVisible="False" SortExpression="batch" /> <asp:BoundField DataFi...

Programmatically reading the selected value of DropDownList in Gridview's Template field
Hi all, I'm reading the content of 2 fields in a Gridview programmatically. For text box, I'm successful with   inv1 = CType(GV_Rows(e.RowIndex).Cells(7).Controls(0), TextBox) follow by a=inv1.text for dropdownlist, I have problem. My code is: inv2 = CType(GV.Rows(e.RowIndex).Cells(6).Controls(0), DropDownList) b=inv2.SelectedValue.Trim  HOwever I run into error: "Unable to cast object of type UI.LiteralCOntrol to type WebControls.DropDownList" Plse help... THank you very much. TOny Instead of using inv2 = CType(GV.Rows(e.RowIndex).Cells(6).Controls(0)...

Gridview Hyperlink Field needs to include value from a previous gridview and a field value
Hi all Hope you can help, here is what I'm trying to do. I have a gridview on a page that contains a value (PracticeCode) I use this value as a parameter to filter an additional GridView (Gridview2). Now what I also want to do is take that value (PracticeCode) and use it in as part of the URL for a hyperlink field in GridView2 concatenatint it with the value of a Gridview field called Documentname so that: Hyperlink field URL Is "/store/" & PracticeCode & "/" and DocumentName Anyone know how to do this  regards chubsterit wasn't me, ...

Manually populating DropDownList control inside a GridView template, can't get it to work, HELP !!
I have a gridview control bound to a table with 2 columns displaying, column 2 was converted to a template field with an unbound dropdown list (name = cmboQTY,  placed inside EditItemTemplate), when an user gets in the edit mode, they select an item off the dropdownlist  my question is, how do I manually populate my dropdownlist on a form_load event ? I tried the following code but keep getting the error that says "Use the "new" keyword to create an object instance", what am i doing wrong, HELP !     Dim tt As New DropDownListtt = CType(GridV...

Update more than one field in a FormView control using a DropDownList/Template field
I am new to .net and what I am trying to achieve is apply some fairly normal business rules, when a user inserts or edits a record in a DetailsView form, in this case a customer claim form. I have setup a template field that does a lookup on an existing Customer table via a DropDownList and allows them to select the customer id to populate the field and this works. I am hoping to also at the same time update the value of the customer name field below customer id in the form when a selection is made. Further down the form I would like to setup a similar situation where I have a site suburb/t...

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

get value in dropdownlist on gridview
hi,im new in, but im facing on trouble problem. i did to add dropdownlist in end cell on i'd like to get selected value of dropdownlist when bounding data in gridview,this is my snip code  protected void grdView_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)    {        if (e.Row.RowIndex != -1)        {            e.Row.Attributes.Add("onmouseover", "

Web resources about - Get Value From A DropDownList Template Field In Gridview - VB -

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 1/17/2016 6:01:59 AM