Open a new page using the Select hyperlink in a datagrid

I have a datagrid that contains information with a Select hyperlink for each row.  How do I reprogram the Select hyperlink to open another form and load that particular record, i.e., it needs to get the column that contains the key and load the record into a FormView?

Thanks
LVL 1
James CochraneB2B FINTECH WRITER/Technology WriterAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
satish_nagdevConnect With a Mentor Commented:
hi,
instead of ItemDatabound for datagrid you can use RowDataBound event for GridView.

regards,
satish.
0
 
YZlatCommented:
Put the following code in the DataGrid's ItemDataBound event:

 If Not e.Item.FindControl("LinkButtonID") Is Nothing Then
            Dim lbtn As LinkButton
            lbtn = e.Item.FindControl("LinkButtonID")
            If Not lbtn Is Nothing Then
                lbtn.Attributes.Add("onclick", "window.open('AddTaskPopup.aspx')")
            End If
        End If
0
 
YZlatCommented:
or

 If e.Item.ID = "Select" Then
            e.Item.Attributes.Add("onclick", "window.open('AddTaskPopup.aspx')")
        End If
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
James CochraneB2B FINTECH WRITER/Technology WriterAuthor Commented:
Hi,

Thanks for that info.  I am using C# and there is no ItemDataBound event in C#.  There is a DataBound event but it doesn't seem to expose E.Item.FindControl.
0
 
YZlatCommented:
it's ItemDataBound
0
 
YZlatConnect With a Mentor Commented:
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.FindControl("LinkButtonID") != null)
{
((LinkButton) e.Item.FindControl("LinkButtonID")).Attributes.Add("onclick","window.open('yourwindow.aspx');");
}
}

or

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ID="LinkButtonID")
{
e.Item..Attributes.Add("onclick","window.open('yourwindow.aspx');");
}
}
0
 
James CochraneB2B FINTECH WRITER/Technology WriterAuthor Commented:
Sorry,

I stated that I am using a DataGrid when I am actually using DataGridView.  The DataGridView doesn't seem to support those properties.

Thanks
0
 
darkpriestConnect With a Mentor Commented:
this is psudeo cause i dont know c#

<TemplateColumn>
<itemTemplate>


<asp:HyperLink runat="serveR" id="linkMe" NavigateURL="~/yourdirectory/page.aspx?a='<%# Eval('YourIDRecord') %>'"</asp:HyperLink>


</itemTemplate>
</Template Column>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.