Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to add Textbox and Drop down controls in Datagrid and manage these controls.

Eg:

Datagrid columns Like

Name Action Comment

Name: shows from Database

Action : Drop down control(Yes/No), suppose if i select Yes then show "Yes" in that colum, if the mouse over or click on that column then show the drop down control.


Comment: User to add comment, if exist then show in that column
Posted

 
Share this answer
 
XML
<asp:GridView AutoGenerateColumns="False" CssClass="grid" ID="gvEmployee" runat="server"
            EnableViewState="False" DataSourceID="sqlDsEmployee" Width="98%" AllowSorting="false"
            CellPadding="0" CellSpacing="0" AllowPaging="false" PageSize="5" PagerSettings-Mode="NumericFirstLast"
            ShowHeaderWhenEmpty="true" OnRowCreated="gvEmployee_RowCreated">
            <RowStyle CssClass="row" />
            <AlternatingRowStyle CssClass="altrow" />
            <Columns>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="S.No">
                    <ItemTemplate>
                        <%# Container.DataItemIndex + 1 %>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Right" Width="4%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Emp No" SortExpression="Empno">
                    <ItemTemplate>
                        <asp:Label ID="lblEmpno" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Empno") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Right" Width="15%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Employee Name" SortExpression="Ename">
                    <ItemTemplate>
                        <asp:Label ID="lblEname" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Ename") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" Width="25%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Job Title" SortExpression="Job">
                    <ItemTemplate>
                        <asp:Label ID="lblJob" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Job") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" Width="20%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Salary" SortExpression="Sal">
                    <ItemTemplate>
                        <asp:Label ID="lblSal" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Sal", "{0:0.00}") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Right" Width="15%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Hire Date" SortExpression="HireDate">
                    <ItemTemplate>
                        <asp:Label ID="lblHireDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "HireDate", "{0:dd/MM/yyyy}") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" Width="15%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="DepName" SortExpression="DNAME">
                    <ItemTemplate>
                        <asp:Label ID="lblDName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "DNAME") %>'></asp:Label>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" Width="30%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Images">
                    <ItemTemplate>
                        <a rel="lightbox" href='<%#Server.MapPath("~/Styles/Images/Desert.jpg")%>' type="text/plain">
                            <asp:Image ID="imgTest" runat="server" ImageUrl='<%#Server.MapPath("~/Styles/Images/Desert.jpg")%>'
                                Width="30px" Height="30px" BorderWidth="0" />
                        </a>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" Width="10%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Update">
                    <ItemTemplate>
                        <asp:Button ID="btnUpdate" runat="server" Text="Update" CssClass="btn" OnClientClick="return ShowDetails(this);" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" Width="10%" />
                </asp:TemplateField>
                <asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Delete">
                    <ItemTemplate>
                        <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="btn" OnClientClick="return ShowDetails(this);" />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" Width="10%" />
                </asp:TemplateField>
                <%--<asp:TemplateField ItemStyle-CssClass="rownum" HeaderText="Test">
                    <ItemTemplate>
                       <%# Eval("DNAME") %>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Right" Width="4%" />
                </asp:TemplateField>--%>
            </Columns>
        </asp:GridView>



Try the above
But first try to google your query if you are unable to get then ask a question
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900