Wednesday, September 17, 2014

Gridview Function

<asp:GridView ID="TrainingGrid" runat="server" ItemType="TrainingTutorial.Entities.Training"
             DataKeyNames="TrainingID" SelectMethod="trainingGrid_GetData"
             UpdateMethod="trainingGrid_UpdateItem"
             EmptyDataText="No training records available."
             OnRowCommand="trainingGrid_RowCommand" PageSize="5"
             AutoGenerateColumns="False" Width="700px" AllowPaging="True" AllowSorting="True"
             <Columns>
                 <asp:TemplateField HeaderText="Action" ItemStyle-HorizontalAlign="Center">
                     <ItemTemplate>
                         <asp:LinkButton ID="approveButton" runat="server" CommandName="Update" CommandArgument="Approved" Text="Approve" Visible="<%# Item.Status == TrainingTutorial.Entities.TrainingStatus.Pending.ToString()  %>"></asp:LinkButton>
                         <asp:Label ID="Label1" runat="server" Text=" | " Visible="<%# Item.Status == TrainingTutorial.Entities.TrainingStatus.Pending.ToString()  %>"></asp:Label>
                         <asp:LinkButton ID="cancelButton" runat="server" CommandName="Update" CommandArgument="Cancelled" Text="Cancel" Visible="<%# Item.Status == TrainingTutorial.Entities.TrainingStatus.Pending.ToString()  %>"></asp:LinkButton>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:BoundField DataField="TrainingID" HeaderText="ID" Visible="false" ItemStyle-HorizontalAlign="Center">
                 </asp:BoundField>
                 <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-HorizontalAlign="Center" SortExpression="Name">
                 </asp:BoundField>
                <asp:BoundField DataField="EffectiveDate" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Effective Date" />

                <asp:BoundField DataField="EffectiveDate"  DataFormatString="{0:HH:mm}"  HeaderText="Effective Time" />
             </Columns>
         </asp:GridView>

OnRowCommand is to click the button of row
e.CommandArgument is get command arguement , e.g. CommandArgument="Cancelled"

DataKeyNames as an agurment for method (Update)
public void trainingGrid_UpdateItem(int trainingID)

No comments:

Post a Comment