Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

gridview and template

Posted on 2011-04-28
5
Medium Priority
?
310 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.
0
Comment
Question by:runnerjp2005
  • 2
  • 2
5 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 35487877
0
 

Author Comment

by:runnerjp2005
ID: 35490291
 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

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35490673
>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?
0
 

Author Comment

by:runnerjp2005
ID: 35490688
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
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 35490710
Ok. Try changing this

<asp:Label ID="lastrep" runat="server" Text="last reply"></asp:Label>

to

<asp:Label ID="lastrep" runat="server" Text='<%= Class1.NoPosts(Eval("Title")) %>' />



Note that I have used Title in Eval assuming that this is the value which is used by the function. You can change that if its not the case.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question