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

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

How do I programmatically iterate through different pages in a GridView?

Posted By:      Posted Date: October 03, 2010    Points: 0   Category :ASP.Net

OK I am a total novice to VB so bear with me.In my web-based project, I pass an ID field as a parameter in my URL and go through each row in my gridview to find the correct row that matches the ID parameter, like so: 

Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.DataBound
 REM if valid ID parameter was given in URL
 If Not Request.QueryString("ID") Is Nothing AndAlso _
  IsNumeric(Request.QueryString("ID")) Then
  Dim bItemNotFound As Boolean = True
  Dim i As Integer
  Dim iSelectedIndex As Integer = -1

  REM Loop through the items in the GridView
  For i = 0 To GridView1.DataKeys.Count - 1 Step i + 1

   REM Found the correct item
   If Request.QueryString("ID") = GridView1.DataKeys(i).Value Then
    bItemNotFound = False
    iSelectedIndex = i
    Exit For
   End If

  If bItemNotFound = False Then
   GridView1.SelectedIndex = iSelectedIndex
   GridView1.SelectedIndex = -1
  End If

 End If
End Sub

The problem is that this code only works if the corresponding ID is in a row displayed on the first page. I want to loop through each page in the gridview's rows until either the correct ID is found or it reaches the end of the data set. How do I

View Complete Post

More Related Resource Links

Programmatically Hide Master Pages from Site Master Page Settings page?



I know there is a field you can check when you edit the properties of a Master Page in the Master Page Gallery to set a Master Page to hidden but ... can anyone think of a way to programmatically hide specific Master Pages from the Site Master Page Settings page?

Maybe this should be two questions:

  1. How do I programmatically access a Master Page in a Master Page Gallery?
  2. Is there a property that can be set that will hide the page from the Site Master Page Settings page?

Help with programmatically set Edit, Update in Gridview


 I'm at the front end of allowing the user to update their data that requires nested gridviews.

I thought I had it set up correctly, but; once I have the grivdiew in Edit mode, when I move the cursor to the first row's textbox, the routine switched out of Edit mode (without a clicking on the Update). I would like to update the data on the screen before the program decides to update the db.

What's causing this?

Here's my aspx page as follows:

<%@ Page Language="VB" AutoEventWireup="false" EnableEventValidation="false" CodeFile="RONs_UPDATING.aspx.vb" Inherits="RONs_UPDATING" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <div id="div_units" runat="server" style="font-size: medium">
        <asp:GridView ID="gv_x_Units" runat="server" AutoGenerateColumns="False" Style="z-index: 100; left: 110px; position: absolute; top: 10p

Programmatically displaying an image in Gridview


Hi Guys,

I need your help!

I have a list of image names stored in a database, along with the id of the property they are associated with. I'd like to be able to display all of the images in a gridview and then allow the user to select the required image.

The problem I'm having is that the gridview is not displaying. I'm pretty sure it's something basic that I've missed, but can't for the life of me see what it is!

Any help would be greatly appreciated!


My gridview code in my aspx page:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">

My code behind (propId is the property id):

        query = "SELECT id, filepath "
                + "FROM images "
                + "WHERE id = ?id";

        MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand();
        command.CommandText = query;
        command.Connection = MyConn;
        command.Parameters.AddWithValue("?id", propId);

        MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter();
        da.SelectCommand = command;
        DataSet ds = new DataSe

programmatically hide the Gridview selectbutton



I want to hide the select button in my grid view programmaticlly in the form startup.

any suggestions how to do this?



editing gridview values to another pages controls


i have a gridview in one form showempdetails.aspx

and another form is to edit the value of selected row editempdetails.aspx

in this page i have textboxes and dropdowns.

im using querystring which is bringing empid

(eg: empid=1 should bind all other columns to my controls of editempdetails.aspx)


below code is of empedit.aspx this takes loginid to employees_add.aspx

grdEmployeesEdit.EditIndex = e.NewEditIndex;

        Label objEmp = (Label)grdEmployeesEdit.Rows[e.NewEditIndex].Cells[0].FindControl("lbl_loginid");
        string id = objEmp.Text.ToString();
        Response.Redirect("~/Employee/employees_add.aspx?loginid=" + id.ToString());

employees_add.aspx.cs i wrote below code

string qslogin = Request.QueryString["loginid"];
        qslogin=objEmployee.P_loginid;//objemployee is my business logic

here by using primary key i should pass all my values of previous selected

Programmatically Add Web Part to the Wiki Pages


Can someone share great resource to add web part to the SharePoint 2010 wiki pages (not web part pages) programmatically? There seems multiple ways to add the web parts on the wiki pages but finding the position is really tricky...

I would like to see the response other than == http://maxshulga.blogspot.com/2010/06/wikieditpageinsertwebpartintowikipage.html and http://mkeeper.spaces.live.com/blog/cns!60F12A60288E5607!478.entry?sa=556111710


Programmatically added linkbutton disappears from gridview on click


I have a gridview with several boundfields and 1 template field that contains a link button. When I click on this link button I want to change one of my bound fields from text to a link button on the affected row. This part works just fine. I click the existing link button and the text in the appropriate field is replaced with a link button. But when I click on the new link button it just disappears. I have been researching this all morning and I believe below are the pertinent facts:

  • I am using the gridview OnRowCommand to capture the link button click and take the appropriate action based on the CommandName
  • I am using the gridview OnRowDataBound to create and add the new link button
  • I am binding the gridview in !IsPostBack

Based off some other posts I read I think that binding the gridview in !IsPostBack is causing the new linkbutton to disappear. How can I fix this? Do I need to add the new linkbutton somewhere other than OnRowDataBound? Do I need to bind the grid somewhere other than !IsPostBack? Am I going about this completely the wrong way?

I am happy to post any of my code, I just was not sure what would be most helpful. I apologize if this has been answered elsewhere. I have found lots of posts with similar situations, but none of them had an answer that I could use.


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.

jQuery: Highlight Gridview Rows with Checkbox

Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

Gridview setup:

Sortable GridView using jQuery's TableSorter

This article explains how to use jQuery's plug-in Tablesorter to implement client-side sorting in an ASP.NET GridView. This comes in handy especially when an ObjectDataSource is used with a GridView as GridView does not provide sorting out of the box.
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