Accessing Gridview Cell Values from inside a Template column

I have a checkbox inside a template field of a gridview, and I need it to respond to a click by appending the key value of the row to a sql statement and executing it.  I have tried using

dim ID as string = MyGrid.SelectedValue.ToString

in the checkbox's OnClick event, but evidently, SelectedValue is populated only if a row is selected using the built-in "Select" button.

I have been advised to add a custom attribute to the checkbox in the GridView's RowDataBound event.  In this context, I can get the value I need in GridView.DataKeys(e.Row.RowIndex).Value.ToString, but I can find no way to add the attribute to the checkbox.

Basically, I need to know how to access the cell values, including the key value, of a Gridview row when a control inside a template field is clicked.

Thanks for your advice.

Sheldon

0
Sheldon
10/9/2005 11:36:27 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
786 Views

Similar Articles

[PageSpeed] 11

I'm in the same situation. Here's what I plan on doing (haven't actually implemented it yet).

Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
   Dim cb As CheckBox = CType(sender, CheckBox)
   Dim row As GridViewRow = CType(cb.Parent.Parent, GridViewRow)
   '*****************************************
   ' I think you can figure the rest out from here
   '*****************************************
End
Sub

0
meganova
10/21/2005 11:42:07 PM
Reply:

Similar Artilces:

Problem Accessing value inside itemtemplate of Gridview with no control inside
I am having a problem to access the value of <%# Eval("item_sku") %> inside ItemTemplate Column. If I use a Label, I don't have any problem to access the control value. Is this a Bug in Asp.net 2.0? The html shows <td></td> tags.             <asp:TemplateField HeaderText="SKU" SortExpression="item_sku">                 <ItemTemplate>                &nb...

How to access GridView hidden Column value by clicking a template column button?
Hi: My GridView contains(for simplicity sake) three columns: a hiden template column that contains the DocID (the DataKey), a template column that contains DocTitle and a template button column that contains a button called btnDetails. When the GridView is loaded with data, the user may click the button on a row and obtain the DocID from the hidden column of that row. This seems to be simple enough. However, when the button is clicked, the GridView always returns blank. Any idea why this happens? My code is as follows: ASPX <asp:GridView ID="gvList" runat=&...

Access value inside gridview cells
Hi, I need access the cell values my gridview control, here are my code:  <asp:GridView ID="gvNBHD" runat="server" Width="935px" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowCommand="gvNBHD_RowCommand" OnRowCreated="gvNBHD_RowCreated" AutoGenerateColumns="False"> <Columns>  <asp:ButtonField CommandName="Note1" Text="NOTE1"/> <asp:ButtonField CommandName="Note2" Text="NOTE2"/>   <asp:TemplateField ...

How do I find a control inside a template inside another template of gridview or repeater?
I have this nested scenario either with the GridView  control or the Repeater control in which in this control "the parent" I have an item template and within that template I put another GridView control "the child" which also has an item template which contains a Hyperlink control. So, that hyperlink control is contained within the template of the gricview that is itself containes within the item template of another control either a gridview or repeater. Now, the child gridview is called "GridView4". What I want to do is set the NavigateUrl property ...

Accessing TextBox value inside Gridview Item Template
Morning!I am trying to find out the values of certain textboxes in a row of a gridview.  Basically I am trying to get a total for a timesheet across 50 columns.  When I try the code below (which is in a method that is triggered each time a row is updated) it gives me the Invalid Object error.  What am I doing wrong?Thanks.Doug.Here is some code...     try            {                col1 = Convert.ToDouble(ActualTimesheet.Rows[0]...

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

Accessing controls inside User control template
Hi, I need to create a user control with one template. That template needs to be like View in MultiView or Wizzard control or Panel. It means, that controls, which are inside should be visible to the page. It will be created just once per control. I need to be able to write :  TextBox1.Text = "Hello world" not : (MyUserControl1.Controls.FindControl("TextBox1") as TextBox).Text = "Hello world" Thanks, radco  If this is a answer to your problem, mark it as answer in right upper corner. It helps other who read your article to known that...

Cannot access a dropdownlist control inside the gridview control
I am using the Gridview control without a DataSource control. When I click on the Edit button, the page posts back and enters the following code: <code>     Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing         Try            Dim row As GridViewRow = GridView1.Rows(e.NewEditIndex)            Dim ddlCustomerID As DropDownList...

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

how to accessing values and set values for a controls that is inside a datagrid
hi this is chandra mohan working as software engineer . here i am having problem with accessing valuse and setting values for controls inside a datagrid. actually i am having datagrid and in this grid i am having item templates of one dropdwon list and text box. i having one Reset link buttion out side the grid(that is in the form) by clicking this Reset Link buttion it should invokes the javascript function and in that function it should set all textboxes of datagrid to  .. txtActionVal.readOnly = true;   txtActionVal.Value ="";and dropdownlist to  dropdownlist...

Accessing child controls inside of a GridView inside of a MultiView
I have a fileupload control which is in a itemtemplate field within the GridView: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="Trk_SqlDataSource">                                <Columns>                                 ...

Clicking templated controls inside <frame>/aspx/UpdatePanel/Gridview cause .net ajax javascript runtime error
I have templated controls in UpdatePanel/Gridview. Clicking the controls in regular aspx will work fine - get postback and updatepanel render fine. If I put the aspx inside frameset <frame>. Clicking controls will cause javascript runtime error - Line: 5820, Sys.ArgumentOutOfRangeException: Value must be an integer. Parameter name: x Actual value was NaN. And updatepanel does not render correctly. Does anyone have same problem, know workaround? Is there anyway to change javascript and incorporate to Web.Extensions.dll?    Sample code: **** MainEntry.aspx - <framese...

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

Web resources about - Accessing Gridview Cell Values from inside a Template column - asp.net.presentation-controls

Highest Percentage Of Opera Mini Users Accessing Facebook? Macau
If you were asked to guess which country had the highest percentage of users of Opera mobile Web browser Opera Mini users accessing Facebook ...

International Users Accessing Facebook Places Through US VPN Accounts
By using a virtual private network (VPN) hosted in the United States, Facebook users from around the world are accessing Facebook Places. The ...

What are some alternatives to Yodlee for accessing bank information?
Clay Loveless , Founder, Jexy. Co-founder, Mashery. Founder, Jexy. Co-founder, Mashery.

Cloud Console - Accessing files in cloud storage for iPad on the iTunes App Store
Get Cloud Console - Accessing files in cloud storage on the App Store. See screenshots and ratings, and read customer reviews.

Meryl Streep On Accessing The Characters Within - YouTube
Meryl Streep talks about the importance of an actors work representing their ability. CONNECT WITH AFI: http://facebook.com/AmericanFilmInstitute ...

Accessing the Future Fund a sensible proposal, says super expert Daryl Dixon
As portfolios go, the Future Fund's asset allocation is concentrated in higher-risk investment, including equities and alternative assets.

Accessing my Super
I'm 57 - can I access my super?

Australia, US accessing Indonesian telephone data, leaked documents show
Newly disclosed documents from former US intelligence contractor Edward Snowden have revealed that Australian intelligence efforts against Indonesia ...

Euthanasia advocate Philip Nitschke detained at Melbourne Airport, accuses Customs officials of accessing ...
Euthanasia advocate Philip Nitschke has accused Customs officials of accessing hundreds of patients' sensitive records on his laptop after detaining ...

Frances Abbott scholarship: Sydney woman pleads guilty to accessing Whitehouse Institute records on PM's ...
A Sydney woman who leaked the student records of Tony Abbott's daughter pleads guilty. A Sydney woman who leaked the student records of Prime ...

Resources last updated: 12/30/2015 9:24:51 AM