We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

gridview and template

Member_2_5230414
on
Medium Priority
321 Views
Last Modified: 2012-05-11
on each row of grid row i want to run this code
    Dim s As String = Request.QueryString("fn")
                Dim Res As Results = Class1.noposts(s)
                Dim lastrep As Label = CType(e.Row.FindControl("lastrep"), Label)
                lastrep.Text = "<u><font color='#284775'>" & Res.Result3.Split("|")(0) & "</font></u><br /> By <b>" & Res.Result3.Split("|")(1) & "</b> <br /> " & timeago.GetDifferenceDate(Res.Result3.Split("|")(2), DateAndTime.Now)

Open in new window


how would i be able to do that as at the moment it returns the same result.
Comment
Watch Question

Miguel OzSenior Software Engineer
CERTIFIED EXPERT
Top Expert 2009

Commented:

Author

Commented:
 Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then

            e.Row.Cells(0).Width = New Unit(50, UnitType.Pixel)

            e.Row.Cells(1).Width = New Unit(500, UnitType.Pixel)

            e.Row.Cells(2).Width = New Unit(100, UnitType.Pixel)
            e.Row.Cells(3).Width = New Unit(100, UnitType.Pixel)
            e.Row.Cells(4).Width = New Unit(220, UnitType.Pixel)
            
            If e.Row.RowIndex <> -1 Then
                e.Row.Cells(0).BackColor = Drawing.Color.White

                e.Row.Cells(4).BackColor = Drawing.Color.White
                e.Row.Cells(2).BackColor = Drawing.Color.White
                e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'")

                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;")
            End If

     

                Dim s As String = Request.QueryString("fn")
                Dim Res As Results = Class1.noposts(s)
                Dim lastrep As Label = CType(e.Row.FindControl("lastrep"), Label)
                lastrep.Text = "<u><font color='#284775'>" & Res.Result3.Split("|")(0) & "</font></u><br /> By <b>" & Res.Result3.Split("|")(1) & "</b> <br /> " & timeago.GetDifferenceDate(Res.Result3.Split("|")(2), DateAndTime.Now)




                Dim lastpostername As String
                lastpostername = e.Row.DataItem("LastPoster")

                e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFFF'")

                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;")


                'lasttime = e.Row.DataItem("lastime")
                If e.Row.DataItem("LastPoster") = "Jarratt" Then

                    lastpostername = "<font color='red'><b>" & lastpostername & "</b></font>"
                Else
                    lastpostername = "<b>" & lastpostername & "</b>"
                End If




        End If

    End Sub

Open in new window

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="forums.aspx.vb" Inherits="Default2" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../Styles/Site.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
 <script type="text/javascript" src="../Javascript/imagecycle.js"></script>
 <script type="text/javascript" src="../Javascript/curvycorners.js"></script>

 </head>
<body>
    <form id="form1" runat="server">
     <div id="top-page-header"><div id="head-wrapper">
  <div id="site-logo">
        <asp:Image ID="Image1" runat="server" 
            ImageUrl="~/images/runningprofilestext.gif" />
        <asp:Image ID="Image2" runat="server" ImageUrl="~/images/rplogo.gif" />
  </div>
      </div></div>
    <div class ="largeMain">
          <div id="maininfolarge" class="forumtd">
              <h2>
                  <strong>Welcome To The <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>&nbsp;Forum&nbsp;
                  </strong>
                     </h2>
                  <div style="float:right">
                      New Topic
                      </div>
           
          
             
              <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                  AutoGenerateColumns="False" CellPadding="4" DataKeyNames="ID" 
                  DataSourceID="AccessDataSource1" ForeColor="#333333" GridLines="None" 
                  Width="970px">
                  <AlternatingRowStyle BackColor="#f9f9f9" ForeColor="Black" />
                  <Columns>
                      <asp:ImageField >
                      </asp:ImageField>
                      <asp:BoundField DataField="Title" HeaderText="Topic" SortExpression="Title" />
                      <asp:BoundField DataField="Auther" HeaderText="Topic Starter" 
                          SortExpression="Auther" />
                      <asp:BoundField DataField="numrep" HeaderText="Replies" 
                          SortExpression="numrep" />

                  <asp:TemplateField HeaderText="Last Post">   
<ItemTemplate>   
    <asp:Label ID="lastrep" runat="server" Text="last reply"></asp:Label>
    </ItemTemplate>   
</asp:TemplateField>



                  </Columns>
                  <EditRowStyle BackColor="#999999" />
                  <FooterStyle BackColor="#001C2A" ForeColor="White" Font-Bold="True" />
                  <HeaderStyle BackColor="#001C2A" Font-Bold="True" ForeColor="White" />
                  <PagerStyle BackColor="#001C2A" ForeColor="White" HorizontalAlign="Center" />
                  <RowStyle ForeColor="#333333" BackColor="#f9f9f9" />
                  <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                  <SortedAscendingCellStyle BackColor="#E9E7E2" />
                  <SortedAscendingHeaderStyle BackColor="#506C8C" />
                  <SortedDescendingCellStyle BackColor="#FFFDF8" />
                  <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
              </asp:GridView>
                                <asp:AccessDataSource ID="AccessDataSource1" runat="server"
                  DataFile="~/forums/forum.mdb" SelectCommand="SELECT * FROM [forum] WHERE Forum=@forum">
        <SelectParameters>
          <asp:QueryStringParameter Name="forum" QueryStringField="fn" />
        </SelectParameters>
              </asp:AccessDataSource><br />
                 </div>
                     
                     <div id="forumstats">
                     </div> 
                     
    </div>
   
    </form>
</body>
</html>

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
>how would i be able to do that as at the moment it returns the same result.

That's probably because you are calling the function with the same query string value for each row.

Do you want to pass the parameter from the row to the function?

Author

Commented:
Do you want to pass the parameter from the row to the function?

thats correct so then i can get the last person to post within that thread
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.