ASP.Net Refresh GridView

2.4k Views Asked by At

Afternoon All,

I am using a visual studio 2010. I have a web page which is used to record minutes of meetings. The page has a section that the user can use to add 'Actions' to the site. I can get a user to successfully add an action to the page.

The issue that i have is i also have a grid view on the webpage and would like this to refresh once the user has added the new 'Action' to the page. So that the user can see that its been submitted.

Im new ish to the .net environment and VB and im not sure 100% how to complete this task.

I have the following code from my .aspx page....

    Submitted Actions:
    <hr />
        <!-- DataSource for submitted Actions -->

        <asp:SqlDataSource ID="OutstandingActionsDS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SMCConnectionString %>" 
            SelectCommand="Populate_grdOutstandingActions" 
            SelectCommandType="StoredProcedure"></asp:SqlDataSource>

        <!-- Gridview that holds submitted Actions -->

        <asp:GridView ID="GridView1" runat="server" DataSourceID="OutstandingActionsDS">
        </asp:GridView>
    <br />
    <br />
        New Actions to Record:
    <hr />

            <!-- Add new Action -->
            <asp:Panel ID="pnlHeaderAction" runat="server" CssClass="pnl" Width="740px">

                <div style="float:left;">
                    &nbsp;Record New Actions
                </div>
                <div style="float:right;">
                    <asp:Label ID="lblShowHideAction" runat="server" ></asp:Label>
                </div>
                <div style="clear:both"></div>
            </asp:Panel>
            <asp:Panel ID="pnlInfoAction" runat="server" CssClass="pnlBody">
               <table> 
    <tr>
           <td  style="width:498px; height: 15px;"><h5>Actions:</h5></td>
          <td style="width:130px; height: 15px;"><h5>Owner:</h5></td>
          <td style="height: 15px;"><h5>&nbsp;Target Date:</h5></td>
    </tr>
    </table>
    <table style="width: 99%">
       <tr>
          <td style="width: 495px">
             <asp:TextBox ID="txtAction" runat="server" TextMode="MultiLine" 
                                Width="493px" Height="50px" style="font-family:Verdana"></asp:TextBox>
           </td>
           <td style="width: 132px" valign="top">
              <asp:TextBox ID="txtOwner" runat="server"  Height="50px" 
                                width="128px" style="font-family:Verdana"></asp:TextBox>
           </td>
            <td valign="top">
              <asp:TextBox ID="txtTargetDate" runat="server" width="89px" style="font-family:Verdana"></asp:TextBox>
            </td>
          </tr>
         </table>
        <br />
             <div style="text-align: right;">
                         <asp:Button ID="btnAddAction" runat="server" Text="Add New Action" CssClass="button" />
              </div>
            </asp:Panel>

Here is my code for the VB page...

      Protected Sub btnAddAction_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddAction.Click

    Dim oActionClass As New ActionClass

    With oActionClass
        .Action = txtAction.Text
        .Owner = txtOwner.Text
        .TargetDate = New SmartDate(Convert.ToDateTime(txtTargetDate.Text))

          oActionClass.ActionID = ActionClassDAL.AddActionClass(oActionClass)
        ClearActions()
    End With

    End Sub

    Private Sub ClearActions()
       txtAction.Text = ""
       txtOwner.Text = ""
       txtTargetDate.Text = ""

    End Sub

This seems like a simple request but i cant seem to find anything that shows me how to refresh the grid based on the user adding the action to the system.

Many thanks in advance for any help offered.

Regards

Betty

1

There are 1 best solutions below

1
On BEST ANSWER

you just have to put a databind to the GridView1. I think is something like this: me.GridView1.databind(); On the bottom of your method btnAddAction_Click.

I hope I have been helpful.