Uncategorized

Binding ASP.Net GridView with Custom Columns

In ASP.Net( aspx ) Markup will be like below :::

<asp:GridView ID="gvTicketDetails" runat="server" AutoGenerateColumns="false">       
                 <Columns>           
            
                       <asp:TemplateField HeaderText="Tk#" >
                            <ItemTemplate>
                                <asp:Label ID="lblTicketNo" runat="server" Text='<%#Bind("TicketNum") %>'></asp:Label>            
                            </ItemTemplate>       
                       </asp:TemplateField>
                    
                        <asp:TemplateField HeaderText="Ticket Title">
                            <ItemTemplate>            
                                <asp:Label ID="lblTaskTitle" runat="server" Text='<%#Bind("TicketTitle") %>'></asp:Label>            
                            </ItemTemplate>       
                       </asp:TemplateField>        
                  
                        <asp:TemplateField HeaderText="Responsible Person" >
                            <ItemTemplate>            
                                <asp:Label ID="lblComment" runat="server" Text='<%#Bind("FirstName") %>'></asp:Label>            
                            </ItemTemplate>       
                       </asp:TemplateField>

                        <asp:TemplateField HeaderText="">
                            <ItemTemplate>
                              <a href="ViewTicketNotes.aspx?TicketNum=<%# Eval("ProjectTicketNum") %>&&ProjectID=<%# Eval("tblProjects_ID") %>&&TblTicketsDetails_ID=<%# Eval("tblTicketsDetails_ID") %>&&TicketTitle=<%# Eval("TicketTitle") %>" target="_blank" >View Ticket Note(s)</a>
                            </ItemTemplate>       
                       </asp:TemplateField>

               </Columns>         
            </asp:GridView>

And The C# code for binding The ASP.Net Grid will be like below :::

DataTable ticketDetaisDT = TicketGateway.GetTicketDetailsForDashboard(projectId, taskStatus);
            gvTicketDetails.DataSource = ticketDetaisDT;
            gvTicketDetails.DataBind();

Standard

Leave a Reply

Your email address will not be published. Required fields are marked *