0 Replies - 250 Views - Last Post: 24 January 2014 - 06:07 AM Rate Topic: -----

#1 inZEFinite  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-January 14

Using RowDataBound or selected index change to chnage button depending

Posted 24 January 2014 - 06:07 AM

I have a DataGrid that has 3 columns one with a button and other 2 gets year from a database. All that I want to do is check if todays date is beween any of the years and if so make one active year. EG: if there was a date for 2014-2015 the button should show active year and the others 'make active year'*if the want to click and make it active...

In my VB code ive tried: Dim today ...``...End If Also I thought about 'Protected Sub grdFinYear_RowDataBound

HTML:
<asp:GridView ID="grdFinYear" runat="server" DataSourceID="dsFinYear" DataKeyNames="FIN_ID" onselectedIndexChanged="grdFinYear_SelectedIndexChanged"
     AutoGenerateColumns="False" ForeColor="#333333" PageSize='20' GridLines="None" AllowPaging="true" SkinID="GridViewSkin" OnRowDataBound="grdFinYear_RowDataBound">>
              <Columns>
                <asp:TemplateField>
                  <ItemTemplate>
                    <asp:Button ID="btnSelect" runat="server" CommandName="Select" CausesValidation="false"  />
                    <asp:HiddenField ID="hdnRecordID" runat="server" Value='<%#Bind("FIN_ID") %>' />
                  </ItemTemplate>
                    <HeaderStyle HorizontalAlign="Left" />
                      <ItemStyle HorizontalAlign="Center" Width="170px" />
                   </asp:TemplateField>
                      <asp:BoundField DataField="FIN_DateStart" HeaderText="Year Start" DataFormatString="{0:D}"
                                                                    HtmlEncode="False" ItemStyle-Width="250px">
                     <HeaderStyle HorizontalAlign="Left" />
                       </asp:BoundField>
                     <asp:BoundField DataField="FIN_DateEnd" HeaderText="Year End" DataFormatString="{0:D}"
                                                                    HtmlEncode="False" ItemStyle-Width="250px">
                      <HeaderStyle HorizontalAlign="Left" />
  </asp:BoundField>
   </Columns>
     </asp:GridView>

VB:
Protected Sub grdFinYear_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdFinYear.PageIndexChanging
        grdFinYear.PageIndex = e.NewPageIndex
        'grdFinYear_RowCreated()

        Dim today As Date = Date.Now
        Dim index As Integer = grdFinYear.SelectedIndex
        Dim Item As String
        Item = grdFinYear.DataKeys(index).Value.ToString()
        If today > Item Then
            grdFinYear.BackColor = Color.Black
            'Dim activeButton As Button = grdFinYear.Rows(0).FindControl("btnSelect")
            'activeButton.CssClass = "ActionButtonsActiveYear"
        End If
        dsFinYear.SelectCommand = "Select * from FinancialYears Order By FIN_Year"
        dsFinYear.DataBind()
        grdFinYear.AutoGenerateColumns = False
        grdFinYear.Visible = True

    End Sub

Some stuff I tried
'Protected Sub grdFinYear_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdFinYear.RowDataBound
    '    Dim ItemID As Int32
    '    Dim index As Integer = grdFinYear.SelectedIndex

    '    If (e.Row.RowType = DataControlRowType.DataRow) Then
    '        DIM Int ItemID AS (Int32.Parse(grdFinYear.DataKeys[index].Values[0].ToString()))
    '    End If
    'End Sub


Is This A Good Question/Topic? 0
  • +

Page 1 of 1