Data Grids and click events

G

Google Jenny

Hello,

I've created a DataGrid (C#) and populated it with data. Here's the
code:

private void PopulateButton_Click(object sender, System.EventArgs e)
{

OleDbConnection MyConnection = new OleDbConnection
(Connection String is here);

OleDbCommand MyCommand = new OleDbCommand();

MyCommand.CommandText = "Select GRADUATES, ROSTERID,"+
"rtrim(LASTNAME) +', ' + rtrim(FIRSTNAME) as NAME from sf1 order by
NAME";

MyCommand.Connection = MyConnection;


try
{
MyConnection.Open();
DataGrid1.DataSource = MyCommand.ExecuteReader();
DataGrid1.DataBind();
MyConnection.Close();
}
catch(Exception ex)
{
//An error occured
HttpContext.Current.Response.Write(ex.ToString());
}


}



What I'd like to do now is make the NAME column clickable so that I can
make things happen when the user clicks on a name in the NAME column. I
don't know how to make anything in a Data Grid clickable.

While I've been able to do this with List Boxes, (Using
SelectedIndexChanged), I have no idea how to do this with Data Grids. I
have a feeling it's a very different paradigm.

Any help most appreciated.

Thanks,
Google Jenny
 
B

Ben

Convert the column into a template column. Inside the template add a link
button. Give the link button a command name & command arguments. Wire up
the datagrids command event. From there, just examine the command name &
agrument inside the DG command event to take action.

HTH,
Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top