Gridview - Changing SelectText of Select CommandField

P

pittster

I'm trying to change the text that is displayed for the Select command
of a CommandField.

I'm figuring that it would have to occur during the RowDataBound event.

Here is the code I've started with (which doesn't work):

protected void GridView2_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CommandField objComField =
(CommandField)e.Row.Cells[0].Controls[0];
objComField.SelectText = DataBinder.Eval(e.Row.DataItem,
"Name").ToString();
}
}

I guess what I really need to know is how to get at the Command field.

If this is impossible, could it be done with a button field, and how...

Thanks
 
U

uanto

This worked for me in vb:

Protected Sub GView_Jobs_RowDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GView_Jobs.RowDataBound
If (e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState =
DataControlRowState.Alternate) _
And e.Row.RowType = DataControlRowType.DataRow Then
Dim SelectButton As LinkButton =
CType(e.Row.Cells(0).Controls(0), LinkButton)
Dim rowView As DataRowView = CType(e.Row.DataItem, DataRowView)
Dim JobTitle As String = CType(rowView("JobTitle"), String)
SelectButton.Text = JobTitle
End If
End Sub
 
Joined
Dec 16, 2009
Messages
1
Reaction score
0
an even simpler solution is...

Code:
If Not IsDBNull(e.Row.DataItem.Item("title")) Then
Dim SelectButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
SelectButton.Text = e.Row.DataItem.Item("title")
 

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

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top