Solved

Gridview update

Posted on 2011-09-28
10
305 Views
Last Modified: 2012-08-13
I am trying to get the following code to update according to a defined timer.  It initializes in the page fine, but does not update according to the timer.

Can anyone help?

Thanks

<asp:View ID="View7" runat="server" ViewStateMode="Enabled">
                    <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                    <ContentTemplate>
                       
                        <table style="width: 100%; height: 20%" cellpadding="0" cellspacing="0">
                                <tr valign="top">
                                    <td style="width: 100%">
                                                                         
                                        <asp:GridView ID="GridView1" runat="server" BorderColor="Gray" BackColor="Gray"
                                        BorderStyle="Inset" BorderWidth="2px" AlternatingRowStyle-BackColor="#CCCCCC"
                                        CssClass="DataGridViewStyle" ForeColor="#FFFFCC" Width="100%" PageSize="10"
                                        HeaderStyle-CssClass="GridViewHeadStyle"
                                        HeaderStyle-BackColor="#336699" HeaderStyle-ForeColor="#FFFFCC"
                                        HeaderStyle-BorderStyle="Inset" HeaderStyle-BorderColor="#CCCCCC"
                                        HeaderStyle-BorderWidth="2" UseAccessibleHeader="False" CaptionAlign="Top"
                                        HeaderStyle-Width="100%" AllowPaging="True" AllowSorting="False"
                                        ViewStateMode="Enabled" DataSourceID="SqlDataSource4"
                                        >
                                        <AlternatingRowStyle BackColor="#999999" />
                                        <HeaderStyle BackColor="#336699" Height="30px"  />
                                           <%-- <asp:dropdownlist id="PageDropDownList"
                                              autopostback="true"
                                              onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
                                              runat="server"/>--%>
                                   
                                    </asp:GridView>
                                   
                                    <asp:Timer ID="Timer8" runat="server" Interval='500'>
                                    </asp:Timer>
                                    </td>                                    
                                </tr>                                
                        </table>
                        </ContentTemplate>
                     </asp:UpdatePanel>
            </asp:View>      
0
Comment
Question by:rckrch
  • 5
  • 5
10 Comments
 
LVL 2

Expert Comment

by:junkymail1
ID: 36720053
I assume you are trying to update the data on the grid?  To do that properly you must handle the timer event properly.

ASP Code:
<asp:Timer ID="Timer" runat="server" Interval="7000" ontick="Timer1_Tick"></asp:Timer>      

C# Code (Handle Event):
protected void Timer1_Tick(object sender, EventArgs e)
 {
            UpdateGrid();
 }

Also, you can wrap the Grid in an update panel and update the grid without a page refresh.  Makes just the grid update and not the page reload.  Just a suggestion. Let me know if you want an example.
0
 

Author Comment

by:rckrch
ID: 36720124
I wraped the grid in an update panel as shown above.  This is what I was trying to do without relloading the enter page.  It has no effect.

I have other instances of using the timer in other areas of the page (not a gridview) with no problem, but this one with the GridView is not working.
0
 
LVL 2

Expert Comment

by:junkymail1
ID: 36720226
Sorry, I didn't notice the panel.  

Just noticed you are missing the
<asp:ScriptManager ID="scriptMgr" runat="server" />      

You need this for the grid to update.
0
 
LVL 2

Expert Comment

by:junkymail1
ID: 36720242
Also, I have seen a few problems with updating the panel from the SQLDataView straight from the Grid.  Have your tried to update the panel from the codebehind like my example?  I haven't had any problems with updating the grid from there.
0
 

Author Comment

by:rckrch
ID: 36720348
I have the <asp:ScriptManager ID="scriptmgr" runat="server"/> earlier in the page.

I tried this code in the code behind - will not work.  I am using vb.net so I don't know how your example would translate.

Thanks for the help.

Protected Sub Timer8_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer8.Tick
        SqlDataSource4.DataBind()

    End Sub
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 2

Expert Comment

by:junkymail1
ID: 36750340
Looking at your code, noticed the Interval='500', is in single quotes. It should be double quotes, like Interval="500". Did you try that?
0
 

Author Comment

by:rckrch
ID: 36815258
Putting it in double quotes did not change anything.
0
 

Author Comment

by:rckrch
ID: 36815632
I put in databind() in the page load for the gridview, but I got an error for invalid DateTime, wrong word at index 0.  Then I put in a error handler and it works fine now.

Why would this be.  If I get an error for one of the columns in the grid why would all the data show up correctly in the grid if I ingnore the error?

Thanks for the help.
0
 
LVL 2

Accepted Solution

by:
junkymail1 earned 500 total points
ID: 36817062
I know that error well.  It just means the row item could not be converted to a date/time.  It usually means a string format problem.  Is the date/time in a string format?  All the data should be there if the data is bound, just the null or strings that can't be converted should not be showing properly.  It also depends on how you bind the data, if you are handling the ItemDataBound event, it could be related to that.  Otherwise the default bind is all except nulls, which is probably why all the data is showing up, converting the date/time is coming back null.
0
 

Author Closing Comment

by:rckrch
ID: 36818907
Thanks

I am using GridView1.DataBind().  The DateTime column is in the DateTime format the database.  Do I need to convert it to make sure I have no errors?  Could this cause a problem down the road?  There really is not a chance of null values in the records.

Thanks for the help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

To effectively work with Diskpart on a Server Core, it is necessary to write some small batch script's, because you can't execute diskpart in a remote powershell session. To get startet, place the Diskpart batch script's into a share on your loca…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

937 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now