Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Selecting and Highlighting Multiple Rows in a DataGrid

Reply
Thread Tools

Selecting and Highlighting Multiple Rows in a DataGrid

 
 
.NETn00b
Guest
Posts: n/a
 
      11-19-2005
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="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="TestMultiSelect.WebForm1" %>
<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="WebUserControl1.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET
7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<uc1:WebUserControl1 id="WebUserControl11"
runat="server"></uc1:WebUserControl1>
</form>
</body>
</HTML>

Code Behind for ASPX page

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestMultiSelect
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
// Put user code to initialize the page here
}

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

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

}
#endregion
}
}

Web User Control

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="WebUserControl1.ascx.cs"
Inherits="TestMultiSelect.WebUserControl1"
TargetSchema="http://schemas.microsoft.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:datagrid 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.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for WebUserControl1.
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button CloseButton;
SqlConnection myConnection;

private void Page_Load(object sender, System.EventArgs e)
{
myConnection = new SqlConnection
("Server=localhost;uid=sa;pwd=preview;database=pub s");

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(dSet, "authors");

DataGrid1.DataSource = dSet.Tables["authors"].DefaultView;
DataGrid1.DataBind();

}



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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting and Highlighting Multiple Rows in a DataGrid Bob Loveshade ASP .Net 1 11-19-2005 09:26 AM
Selecting and Highlighting Multiple Rows in a DataGrid .NETn00b ASP .Net Datagrid Control 0 11-19-2005 03:34 AM
Datagrid: Selecting multiple rows/cols PontiMax ASP .Net Datagrid Control 1 02-21-2005 03:06 AM
DataGrid: Selecting multiple rows/cols PontiMax ASP .Net 0 01-12-2005 01:15 PM
selecting multiple rows datagrid javascript Jay ASP .Net 1 10-15-2003 03:53 PM



Advertisments