473,561 Members | 3,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting and Highlighting Multiple Rows in a DataGrid

I am looking for an example that shows how to select and highlight
multiple rows in a DataGrid.

My DataGrid is part of a Web User Control which is contained in an ASPX
page.

I haven't been able to find any examples which demonstrate how to do
this.

My Code:

The ASPX Page

<%@ Page language="c#" Codebehind="Web Form1.aspx.cs"
AutoEventWireup ="false" Inherits="TestM ultiSelect.WebF orm1" %>
<%@ Register TagPrefix="uc1" TagName="WebUse rControl1"
Src="WebUserCon trol1.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " Content="Micros oft Visual
Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript"
content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<uc1:WebUserCon trol1 id="WebUserCont rol11"
runat="server"> </uc1:WebUserCont rol1>
</form>
</body>
</HTML>

Code Behind for ASPX page

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace TestMultiSelect
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{
private void Page_Load(objec t sender,
System.EventArg s e)
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
// Form
// Designer.
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}

Web User Control

<%@ Control Language="c#" AutoEventWireup ="false"
Codebehind="Web UserControl1.as cx.cs"
Inherits="TestM ultiSelect.WebU serControl1"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5"%>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300"
border="1">
<TR>
<TD colSpan="3">
<div style="OVERFLOW : auto; WIDTH: 100%; HEIGHT:
200px"><asp:dat agrid id="DataGrid1" style="Z-
INDEX: 102;
LEFT: 24px; POSITION: absolute; TOP: 32px"
Height="120px"
runat="server"> </asp:datagrid></div>
</TD>
</TR>
<TR>
<TD></TD>
<TD align="center">
<asp:Button ID="CloseButton " runat="server"
Width="99px"
Text="Close"></asp:Button>
</TD>
<TD></TD>
</TR>
</TABLE>

Web User Control - Code Behind

namespace TestMultiSelect
{
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Data.Sql Client;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

/// <summary>
/// Summary description for WebUserControl1 .
/// </summary>
public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Data Grid
DataGrid1;
protected System.Web.UI.W ebControls.Butt on
CloseButton;
SqlConnection myConnection;

private void Page_Load(objec t sender,
System.EventArg s e)
{
myConnection = new SqlConnection
("Server=localh ost;uid=sa;pwd= preview;databas e=pubs");

if(!IsPostBack)
BindGrid();
}

public void BindGrid()
{
SqlDataAdapter dAdapter = new SqlDataAdapter
("SELECT au_id,
au_fname, au_lname FROM authors ",
myConnection);
DataSet dSet= new DataSet();
dAdapter.Fill(d Set, "authors");

DataGrid1.DataS ource = dSet.Tables
["authors"].DefaultView;
DataGrid1.DataB ind();

}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET
// Web Form
// Designer.
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not
/// modify
/// the contents of this method with the code
/// editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler
(this.Page_Load );

}
#endregion
}
}
I want to select the au_fname and au_lname fields (which I am going to
concatenate). The Web User Control has a Button which, when clicked,
should pass the selections to the calling page (a simple HTML page).
Clicking the button should also close the .ASPX page, and refresh the
calling page.

Is what I am trying to do reasonable, or is there a better approach? I
am a bit out of my depth here, and would really appreciate any kind of
help, especially code snippets.

Thanks!


*** Sent via Developersdex http://www.developersdex.com ***
Nov 20 '05 #1
1 3331
Hi Dear Bob Loveshade,

Why don't you achieve the same thing by CheckBox Select Multiple Rows
Column

here are some good articles

1. HOW TO: Loop Through and Examine CheckBox Control Values in a
DataGrid Column by Using ASP.NET and Visual C# .NET
=============== =============== =============== =============== ==

http://support.microsoft.com/default...b;en-us;320707
2. HOW TO: Loop Through and Examine CheckBox Control Values in a
DataGrid Column by Using ASP.NET and Visual Basic .NET
=============== =============== =============== =============== ==

http://support.microsoft.com/default...b;en-us;321881
3. DataGrid CheckBox Select Multiple Rows Column
By Noman Nadeem
=============== =============== =============== ===

http://www.codeproject.com/aspnet/dgcheckboxcolumn.asp
4. Selecting multiple checkboxes in a DataGrid control
By azamsharp
=============== =============== =============== ==========

http://www.codeproject.com/aspnet/da...Checkboxes.asp
5. Selecting, Confirming & Deleting Multiple Checkbox Items In A
DataGrid (i.e. HotMail & Yahoo)
=============== =============== =============== =============== ==

http://www.dotnetjunkies.com/Tutoria...393-3D0E0F024E
C0.dcik

bye
venkat_kl

For Anything and Everything, Please Let Me Know

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1538
by: Dave | last post by:
Hi all, Apologies if this is the wrong group. I have done a search on google but my keywords are probably no good. What I want to do is to display a list of data in a datagrid (which I have already done). At the side of the list, I want to put in a checkbox, basically to select that line.
6
2047
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I need to use parts of the tables in datagrids, and here is where my problem lies
2
2145
by: ___Newbie___ | last post by:
Hello, I'm looking for a control that can display rows and columns similar to a table but highlight the entire row during selection? Listbox highlights the entire row but doesn't support multiple columns. DataGrid on the other hand supports multiple columns but I can't able to highlight the entire row. It does a column and row level...
1
2229
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that caused me other problems. Any ideas? Thanks, Jay
1
1188
by: Dan | last post by:
I'd like to let a user select multiple rows from a Web Form datagrid, and then perform actions on the selected rows when I get a postback. How would I do that? Dan
0
1049
by: PontiMax | last post by:
Hi, I would like to enhance the DataGrid by adding scripting functionality that allows the selection of multiple rows or columns via drag-and-drop. Can anyone provide some examples or references? Many thanks in advance, P.
1
2908
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we have written the code using radio button for selecting single item.but we want to replace it with checkbox to select multiple items. the code...
0
324
by: .NETn00b | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been able to find any examples which demonstrate how to do this. My Code:
4
3742
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure and username, password etc will be exactly the same for each server, the only thing that will change is the server name. Idealy I would like to get...
0
7565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8079
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7611
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3613
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2062
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.