.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

gridview cell value via FindControl......

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

I have a page that is using an unbound gridview, that has a mixture of template based columns (drop down list, text boxes, etc).  I've tried the following syntax to retrieve the values currently in the cells.


 TextBox1.Text = grdDataEntry.Rows(1).FindControl("mydropdownlist").ToString        

TextBox2.Text   = grdDataEntry.Rows(1).FindControl("mytextbox").ToString


What am I missing???

View Complete Post

More Related Resource Links

GridView EmptyDataTemplate and FindControl Method


I have 2 textboxes, a dropdownlist and a button in the EmptyDataTemplate of a GridView control and when I click the button I want to get the text from the text boxes and DropDownList put it in the QueryString of a URL i redirect to, but I can't work out why the FindControl method cannot find the controls.  I am using the following code:

Dim ddlNumPpl As DropDownList = GridView1.FindControl("ddlNumPpl")

I get an "Object reference not set to an instance of an object" error though when I try to refer to the SelectedValue property of it though.  I would be very grateful if someone could let me know why the FindControl method can't find the control and what I should do to rectify it.

Many Thanks (in advance),


How can i add a textbox into a GridView Cell dynamically and how can i retrieve entred data

Hey, i think that the the subject can explain what i need, it's about adding a TextBox control with the code behind into a GridView, and also about how can i retrieve entered data after submitting, im using C#,Thanks.

I need to set the value of a gridview cell during update.

Hi,  I've been reading the posts here and I'm not finding, or maybe just not understanding, the answer I need so here's my problem. I have a small gridview and the update works very well. The issue is I need to have one of the fields set to a value from my code either when the record is open for undating or when the update runs.  Here is my gridview and the datasource info:<asp:GridView ID="GridViewItemLog" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" CellPadding="3" DataKeyNames="LogID" DataSourceID="SqlDataSourceItemLogEntries" GridLines="Vertical" onrowdatabound="GridViewItemLog_RowDataBound" onrowupdating="GridViewItemLog_RowUpdating" onrowediting="GridViewItemLog_RowEditing"><AlternatingRowStyle BackColor="Gainsboro" /><Columns><asp:CommandField ButtonType="Image" CancelImageUrl="~/Resources/StopSmall.png" EditImageUrl="~/Resources/EditSmall.png" ShowEditButton="True" UpdateImageUrl="~/Resources/Save.png" /><asp:Boun

ASP.NET GridView help!! Need to be able to scroll an individual cell up and down.

Hi everyone.  I have an ASP.NET GridView displaying the below grid.  As you can see, the column on the right has a LOT of text and it stretches the column.  I need to be able to set a fixed width for JUST that column (maybe like 200px) and have vertical scroll bars on that cell so the user could scroll down to read the rest of the text, is that possible to do?Here's my markup: <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="False" AllowPaging="True" AlternatingRowStyle-Wrap="False" CellPadding="4" ForeColor="#333333" GridLines="None"> <RowStyle Height="30px" BackColor="#EFF3FB" /> <Columns> <asp:BoundField DataField="Customer_Name" HeaderText="Customer" SortExpression="Customer" /> <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" /> <asp:BoundField DataField="Module" HeaderText

findcontrol problem in a gridview

Hey guys I've got a gridview with a few textboxes in each row which I want to insert into a database, after a user clicks a submit button (thats outside of the gridview)  This is my code for the gridview<asp:GridView ID="GridView2" AutoGenerateColumns="false" runat="server" EnableModelValidation="True"> <Columns> <asp:TemplateField > <ItemTemplate> name: <asp:Label ID="Label12" runat="server" Text='<%# Bind("PlayN") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="TxtFirst" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="txtLast" runat="server"></asp:TextBox> </ItemTemplate>

Javascript code to copy specific cell of gridview row

Dears, I need a javascript code to copy the text content of a cell of a row in gridview. I have a button in each row that users click it and the text content a cell of that row should be copied in a textbox out of gridview

Gridview Cell Hightlight with toggling

Hi, I have a dynamically generated Gridview wherein every tablecell within the gridview is assigned a particular class(background color) at run time. Each cell has  a linkbutton and I have a onClientClick event where, I would like to highlight the container cell when the user clicks on the linkbutton.If the user clicks it back, I would it to  get back its original class/background color that it was bound with earlier. I am trying to implement this in Javascript by passing the original className but I am unable to toggle the color back to original.Please help. Here is a snippet of code. I could do it in c# but I would like to implement this in Javascript as it won't  cause postback.Thanks so much!//Linkbutton databinding event private void lb_DataBinding(Object sender, EventArgs e)     { private void lb_DataBinding(Object sender, EventArgs e)    { LinkButton l = (LinkButton)sender; l.OnClientClick = String.Format("doClick({0},{1},'{2}','{3}','{4}','{5}','{6}'); return false;", x, y, className, tbPercentSoldUpfrontSelected.ClientID, tbPercentChangeDemandSelected.ClientID, tc.ClientID, l.ClientID);} function doClick(val1, val2, val3, control1, control2, control3, control4)         {         &nbs

Gridview's cell have changed



   does anyone know if the gridview can tell you if a cell's contents have changed (during an edit) in order to determine if an update should be made against the database?

How Get selected cell values from gridview


How Get particular selected cell value from gridview . my grid so many cell available..

i'm created dynamic row and cell ...

How to Retrieve the Hidden Cell value in GridView -- Urgent ************


Hello all,

In my GridView I have Hidden column contains ID. When User selects the rows and clicks on Delete Button( This is placed top of the Grid) Selected Rows will be deleted.

my delete button code is ...

foreach (GridViewRow dgi in Grid_Inbox.Rows){

CheckBox chkSelected = (CheckBox)dgi.FindControl("chk_Select");

if (chkSelected.Checked == true)


string strID = dgi.Cells[1].Text;

//Delete the Rows



//Binding the Grid



problem is when i am accessing through the code. getting cell value as bla

Gridview Cell Merging


Hi All,

I have a grid, where i need to do cell merging till certain columns. It is working and the code is as follows.

Friend Shared Sub GridviewCellMerge(ByRef gridViewControl As GridView, ByVal colStart As Integer, _
                                            ByVal colLast As Integer)
            For rowIndex As Integer = gridViewControl.Rows.Count - 2 To 0 Step -1
                Dim gvRow As GridViewRow = gridViewControl.Rows(rowIndex)
                Dim gvPreviousRow As GridViewRow = gridViewControl.Rows(rowIndex + 1)
                For cellCount As Integer = colStart To colLast
                    If gvRow.Cells(cellCount).Text = gvPreviousRow.Cells(cellCount).Text Then
                        If gvPreviousRow.Cells(cellCount).RowSpan < 2 Then
                            gvRow.Cells(cellCount).RowSpan = 2
                            gvRow.Cells(cellCount).RowSpan = gvPreviousRow.Cells(cellCount).RowSpan + 1
                        End If
                        gvPreviousRow.Cells(cellCount).Visible = False
                    End If
        End Sub

1. a  b  c  d

2. a  b  c  e

3. a  b  f  e

4. a  b  f  e

5. a  b  g 

Accessing gridview cell values


Hi All,

In my application Iam using GridView, in this there are fields (Quantity, Price, Amount) the user can enter Quantity Field value which is a template field (textbox). Iam calculating Amount(Quantity * Price) using Javascript and assigning to the Amount Column cells as below

Gridviewcell.innerText=Quanity * price.

and when user clicks on the Save button I want to add these details of Gridview to the database.

when I try to access the values of the gridview using below code

For i=0 to GridView.rows.count-1

GridView.Rows(i).Cells(2).toString ( for Example)

Next i

It is not displaying the changed value instead it is displaying the default value before calculating the amount.

Before implementing the Javascript part, I had done this in the code behind and it was working fine... Now I just dont want the page to get load so I used javascript.

Can any one help me out in able to access the value of Gridview cells which are assigned using Javascript.



changing Asp.net Gridview's cell from Label to edit mode in code behined file


 Hi all,

In my asp.net application i'm using gridview to which i'm binding data dynamically by writing a select query in code behined file (all column's are autogenerated) now i want to change gridview cell to edit mode from label to textbox or dropdown on clicking of gridview's cell.How can i achive this in code behined file.

thanks in advance

Why it returns null (GridView)TemplateContainer.FindControl("gridView")?



I created a new custom field definition.

But on CreateChildControls event it always return null in my components. Where is error? What should I do to make work it properly?


protected override void CreateChildControls()


if (this.Field == null) return;


if (this.Field != null && this.ControlMode!= SPControlMode.Display)

this.MyPrefix = (Label)TemplateContainer.FindControl("MyPrefix");
if (this.MyPrefix == null)
    throw new ArgumentException("Corrupted PermissionControl template - missing ProofHQUserPermissionPrefix.");
this.gridView = (GridView)TemplateContainer.FindControl("gridView");
if (this.gridView == null)
    throw new ArgumentException("Corrupted PermissionControl template - missing GridView.");



All components are defined in template PermissionControl.

How to make a cell editable in gridview?


I was trying to create a gridview which should allow to edit a perticular cell on clicking on it. But is not working as expected. Here is my code. Can anyone tell whats the issue with this.

<Window x:Class="Window1"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="Window1" Height="279" Width="672">

        <Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}" >
            <Setter Property="Background" Value="#00ffffff" />
            <Setter Property="BorderBrush" Value="#00ffffff" />
            <Setter Property="Acce

GridView and FindControl issue..


Hi guys,

I dont seem to find any control using the FindControl method over gridviews "on edit". I have pasted my code below, please tell me if m doing something wrong or missing something..

ASPX page:

<asp:GridView ID="gvCountry" runat="server" AutoGenerateColumns="False" 
                <asp:TemplateField HeaderText="Edit">
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update"></asp:LinkButton>
                         <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 

How can a fill a cell in a gridview in a windowsform?


I have a gridview in a windowsform.
There are 4 columns (A, B, C and D).
I column D is a combobox.
How can I fill this combobox at form_load with the following data: --> 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend