Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds


  Asked By: Erin    Date: Jan 08    Category: Sharepoint    Views: 1763

I am using the SPGridView in a number of my custom webparts - I need to
make a column in each of the rows selectable. I don't want to have
the "Select" word in the first column. Does anyone know how to make
the text in my first column selectable?



3 Answers Found

Answer #1    Answered By: Debbie Snow     Answered On: Jan 08

I've done this in the past, but don't have the code right in front of me so I
don't remember the exact events or items. But in general the procedure is as

Intercept the event that represents the data being bound to the row. I think
its titled something like the DataRowBinding event. In the handler for that
event replace the contents of the first cell with a new control (I think I used
a HyperlinkButton or something like that.). Set the text  and command properties
of the HyperlinkButton to whatever you want the link to read. This will
generate a hyperlink in that cell of the row. Have the command set so you can
Identify the row selected. Then when the user clicks on that row there will be
a postback and you can do what needs to be done with that row. In my case it
was to drill down to details on that row of the grid.

If you can't figure out which event and which object to use let me know and I'll
dig out the details from my old code.

Answer #2    Answered By: Adalberto Merrill     Answered On: Jan 08

Can you please dig out the source for this functionality?

Answer #3    Answered By: Lynsey Carver     Answered On: Jan 08

I figured it out so I thought I would share with others:

Inside the webpart:

protected NameValueCollection parameters;

protected override void CreateChildControls()

// get the parameter that is passed in on the URL
parameters = Context.Request.QueryString;

gvSchools = new SPGridView();
gvSchools.ID = "gvSchools";
gvSchools.AutoGenerateColumns = false;
gvSchools.AllowSorting = true;
gvSchools.Sorting += new GridViewSortEventHandler

HyperLinkField colName = new HyperLinkField();
colName.DataTextField = "SchoolName";
colName.HeaderText = "School Name";
colName.SortExpression = "SchoolName";
colName.DataNavigateUrlFields = new string[]
{ "SchoolName" };
= "http://SharePointBox/Test/default.aspx?ID={0}";

BoundField colName2 = new BoundField();
colName2.DataField = "Active Status";
colName2.HeaderText = "School Active?";
colName2.SortExpression = "Active Status";

gvSchools.SelectedIndexChanged += new EventHandler

oView = new DataView(dsSchools.Tables[0]);
gvSchools.DataSource = oView;

Didn't find what you were looking for? Find more on SPGridView Or get search suggestion and latest updates.