views:

198

answers:

1

I have an asp.net page with a custom usercontrol which contains a selectable gridview, and a formview which is on the page directly.

First issue: I want the FormView's pageindex to be the selected index of the GridView. I can get the selectedindex of the GridView by doing this:

public virtual int SelectedIndex
    {
        get { return this.GridView1.SelectedIndex; }
        set { this.GridView1.SelectedIndex = value; }
    }

Then on my aspx page I can do this:

FormView1.PageIndex = CodeView1.SelectedInex;

The problem is that I can't seem to figure out how to call this function from within my aspx page for whenever I click the Select link of a row on my gridview. I've assigned it to a button onclick just to make sure it works, and it does. I'd just like to be able to do it from the gridview directly.

Second Issue

On the gridview (the same one as above), I have an itemtemplate for the select command which is an asp:linkbutton. Whenever I click the Select link on the gridview, all the formatting that I've set up in the rowdatabound function gets undone.

For example, I have this in my rowdatabound:

HyperLink TicketDetailLink = new HyperLink();
TicketDetailLink.NavigateUrl = "TicketDetail.aspx?TicketNumber=" + TicketNumber;
TicketDetailLink.Text = TicketNumber;
e.Row.Cells[5].Controls.Add(TicketDetailLink);

But as soon as I click my select link, that hyperlink disappears. Thoughts?

+1  A: 

First Issue:

        string key;

        LinkButton myLink = (LinkButton)sender;
        GridViewRow gridview = (GridViewRow)myLink.Parent.Parent;

*Assign2Control*= gvManagePlanning.DataKeys[gridview.RowIndex].Value.ToString();.

This is how i get the value from my gridview. Add a templatefield to you gridview and put a linkbutton in it. Put this code in the onclick event. Add the value you want to retrieve to the datakeynames so it gets stored in the Datakeys. You will have to change the datakey index if there is more than one datakeys.

Second Issue:

      <asp:HyperLink ID="HyperLink1" runat="server" 
NavigateUrl='<%# Eval("TicketNumber", "TicketDetail.aspx?TicketNumber={0}") %> 
    Text="TicketNumber"></asp:HyperLink>
Jordan Johnson