Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

manipulating data in a gridview 1

Status
Not open for further replies.

NuJoizey

MIS
Aug 16, 2006
450
US
I have a gridview that spits out a column like this:

status
------
open
closed
pending
open
closed


I want to capture the 'closed' iteration and make the word 'closed' it into a hyperlink that you can click on to take you to another page with more info.

i should be able to do this using vb in my codebehind, shoudn't I? - but i'm having trouble with the syntax and I don't know what properties/methods to manipulate - help?
 
add a template column to the grid for the status property.
in the RowDataBound code behind determine what the status is and adjust the template as necessary
Code:
<asp:GridView ... RowDataBound="myGridView_RowDataBound">
   <Columns>
      ...
      <asp:TemplateColumn HeaderText="Status" >
         <ItemTemplate>
            <asp:HyperLink id="StatusLink" runat="server" />
         </ItemTemplate>
      </asp:TemplateColumn>
   <Columns>
</asp:GridView>
Code:
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if(e.Row.RowType == RowType.DataRow)
   {
      DataViewRow row = (DataViewRow)e.Row.DataItem;
      HyperLink link = (HyperLink)e.Row.FindControl("StatusLink");
      if(link != null)
      {
         if (row["Status"] == "Closed")
         {
            link.NavigateUrl = "[url goes here]";
         }
      }
   }
}
you'll need to translate this into vb.
if your gridview datasource is not a datatable/view you'll need to change the type you convert it to.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
great! here is what i came up with in VB:

Code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
       
If e.Row.RowType = DataControlRowType.DataRow Then
    If e.Row.DataItem("MarketingStatus").ToString = "Closed" Then

                Dim hl As HyperLink = e.Row.FindControl("hlStatus") : hl.NavigateUrl = "mylink.aspx"
            End If
        End If

    End Sub

thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top