.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

Find a gridview row by keyfield value

Posted By:      Posted Date: September 17, 2010    Points: 0   Category :ASP.Net
Hi All,   I have 2 Tables Branches and UserAssigned branches. I use a Gridview and bind a datasource from the Branches table to display all branches on the Gridview. Next,  I want to mark the branches which are assigned for a user (using checkbox field on gridview item template) as checked. I have a List<UserBranches> which contains a list of BranchIds assinged for a given user. Now to check those branches on the gridview, I need to find the rows with the same branch Id as the ones in the list. Is there anyway to do this without using foreach (Gridview row in gvBranches){} becasue I'm afraid I have to use 2 inner loops - one to iterate through the items in the list and one to iterate through the Gridview rows. Instead, I was wondering if I could do the following way: foreach (int branchId in UserBranchList) { //find the gridview row with the Key branchId //get the checkbox in the row and mark it checked } is this possible? If so please tell me how to do it Thanks

View Complete Post

More Related Resource Links

find a Control inside a GridView using jQuery


I have databound GridView in my page and I have a hidden DIV in all rows. Each row contains a Button that I want it to make the DIV visible for me! how can I use that with jQuery?!

here is the code page: 

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                                EnableModelValidation="True" GridLines="None" ShowHeader="False" Width="100%">

How to find specific nested object type in Gridview

Dears, I have a gridview with a nested placeholder in each rows. I nested some checkboxes in each placeholders in each rows dynamically, so their ServerIDs are not the same (I dont want to use nested gridview). at the end in a button event I want to count checked checkboxes in gridview while I can not use findcontrol() method in each rows to find checkboxes due to their different ServerIDs. How can I do this?

find the label control of gridview in save button event in C#

hi, every one..i want save the gridview in buttonsave event..here i wrote the code like thisfor (int i=0;i<gridview1.row.count;i++){label lbl=(label)gridview1.rows[i].findcontrol("lbl");Textbox txtname=(Textbox)gridview1.rows[i].findcontrol("txtname");}here i got the textbox value but am not getting label value how to get that label value..thanks in advance

WPF : Find a control in GridView

I have googled a lot to find the answer to my question but no suitable answer could be found. I am using a gridview of wpf tool kit. which has multiple columns  column structure is like,   <my:DataGridTemplateColumn MaxWidth="15" MinWidth="15" Width="15"> <my:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Button Click="btnContractCollespe_Click" FontSize="9" Height="20" Name="btnContCollespe">+</Button> </DataTemplate> </my:DataGridTemplateColumn.CellTemplate> <my:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate /></my:DataGridTemplateColumn.CellEditingTemplate> </my:DataGridTemplateColumn> <my:DataGridTemplateColumn> when grid renders it displays button "btnContCollespe" in each row. I want some how I could change contents of every button in all rows. Basically this button will expand and collapse gridview 3 fixed columns. so upon expand operation, buttons in all rows should have content "-" and after user performs collapse operation, all button content should change to +. I found no suitable way to find control inside grid. Can anybody help. In asp.net we used to do it by gridview.findcontrol("...") but no such method is available in WPF gridview. please provi

gridview find invisible row from code behind


hi all,

let me explain completly. I designed an gridview, header template i added one textbox and button if the user enter something on Txtbox and click button then based on input i show corresponding rows only, all other rowss will be hidded using Javascript like below

tblOrders.rows[CurrRow].style.display = 'none';

now im doing something on the Gridview_RowCommand event at this time the gridview got refreshed so that the hiden rows are visible, but i dont want to show the hidden(invisible) rows while rowcommand event fired. so, is there any way to solve this issue?

experts please help me to resolve this...........!

find textbox control of gridview using javascript



 I am inserting a data in gridview row. I have 2 textbox's, 1 label and 1 textbox respectively. Here, I want to do calculations on data which is in first two textboxes and result should be displayed in label and the text in label to be multiplied with 40 and that should be displayed in last textbox.

 This operation to be done in onblur() event of second textbox. To do this I need to find the controls in gridview in onblur() event of the textbox.

  I tried to do this in .cs file but this operation is to be done before inserting in to database on that particular row of gridview.

I searched on the net but i couldn't find the solution. I couldn't know how to find textbox of a gridview using javascript

Please help me.....

Gridview Loop through find total of labels with same value


Hey :)

I would like to know if someone can please help me

How can I loop through and find the TOTALS of all labels with the same values


For Each gvrow As GridViewRow In InsertedCompanies.Rows

Dim lblRegistrationComplete As Label = DirectCast(gvrow.FindControl("lblRegistrationComplete"), Label)

Dim lblIsJobPayedFor As Label = DirectCast(gvrow.FindControl("lblIsJobPayedFor"), Label)

Dim lblOutstanding As Label = DirectCast(gvrow.FindControl("lblOutstanding"), Label)

Dim lblJobPayedPrice As Label = DirectCast(gvrow.FindControl("lblJobPayedPrice"), Label)


If lblRegistrationComplete.Text = "True" And lblIsJobPayedFor.Text = "False"  Then

                lblOutstanding.Text = "Outstanding"
                lblOutstanding.Text = "Not Outstanding"


Find and Set DetailsView Controls In Empty Data Template in Gridview



I would like to find controls in the detailsview control placed in the EmptyData Template of the gridview.   I am trying to create Insert new record for the gridview control.

1. If there are existing records in the table - works fine and sets my two values:
 placed Detailsview and Insert Button in the footer of the gridview.  I needed to set the values of two fields.  When I click on the Insert button it saves new record and sets the field with the value (code attached - works fine).  I also have a popup extender that opens detailsview - this works just fine.

2, If ther are not records in the table - saves record but cannot find and set controls on the detailsview
Same thing setup in the EmptyData Template.  The record is saved but I cannot Find and set the field value on the control.

Here is code:

1.  Link button (on click) in the gridview footer (works fine)

protected void LinkButton1_Click1(object sender, EventArgs e)


        string zupa1;

        zupa1 = ddlSelectEmployee.SelectedValue;





Find Complete row in rowcommand in Gridview.



In my database table I have ID,FirstName,LastName,Address fields.I have bound the FirstName,LastName in Gridview with Eval Method.But have not bound the address coz I m not dispalying address.

Now there are textboxes below the gridview which gets filled when I click the edit button in gridview with  values in the gridvoew row.I am getting the FirstName and LastName (using find control in rowcommand) but not the address.How can I get the address without hitting the database again.

Inplace Edit in GridView

In this article I am presenting a different way to look at EditItemTemplate, using which user navigation for editing is reduced and . it looks very different (see screeen shots) then regular implementation of GridView.

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

AJAX GridView Checkbox Select All in ASP.Net

In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

AJAX GridView Paging and Sorting using C# in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Paging Using Ajax in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

Displaying Row Details Tooltip on GridView using JQuery

Continuing exploring JQuery! I decided to implement a feature to display some kind of details related to a row displayed on GridView. For example when displaying employees details on GridView some information might not fit in the GridView because it will make it huge and wide. These infomration can be diplayed as Tooltip. Or when you want to display a picture and some kind of formated text to be diplayed as tooltip when mouse hover on the image.
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