Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can we use gridview in usercontrol using asp.net. I want add gridview control to all the forms in my application.any idea...
Posted

ASP.NET
<asp:GridView ID="grdCategory" runat="server" AutoGenerateColumns="False" Width="1100px"
                    DataKeyNames="CourseCatID" Font-Names="verdana,arial,helvetica,sans-serif" Font-Size="8pt"
                    CellPadding="4" ForeColor="#333333" GridLines="None">
                    <Columns>
                        <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="False" />
                        <asp:BoundField HeaderText="CourseCatID" Visible = "false" DataField="CourseCatID" />
                        <asp:TemplateField HeaderText="Course Category">
                            <ItemTemplate>
                                <asp:Label ID="lblCourseCatID" runat="server" Visible="false" Text='<%# Eval("CourseCatID")%>'></asp:Label>
                                     <a href="java<!-- no -->script:toggleDiv('mydiv<%# Eval("CourseCatID")%>')">
                                     <asp:TextBox ID="txtCourseCatName" runat="server" Text='<%# Eval("CourseCatName") %>' Font-Size="XX-Small"
                                Font-Names="Verdana" Width="300px" Visible="false"></asp:TextBox>
                                    <asp:Image ID="img" onclick="javascript:Toggle(this);" runat="server" ImageUrl="~/Images/minus.gif"
                                        ToolTip="Collapse" Width="7px" Height="7px" ImageAlign="AbsMiddle" /></a>
                                <asp:Label ID="lbllastname" Height="15px" runat="server" Text='<%# Eval("CourseCatName")%>'> </asp:Label>
                                <div id="mydiv<%# Eval("CourseCatID")%>">


                                    <br />
                                        <%--OnClick="ImageAdd_click" --%>
                                    <asp:ImageButton ID="ImageAdd" Height="17px" ImageUrl="Images/addCourse.png" runat="server"
                                        CommandName="cmdAdd" CommandArgument='<%# Eval("CourseCatID") %>' />
                                        <br />
                                        <br />


                                    <asp:Panel ID="pnlCourse" runat="server"></asp:Panel>
                                    <cuc1:CourseUserControl ID="CourseUserControl1"  runat="server" />
                                    <br />

                                    <br />
                                     <br />
                                      <br />


                                </div>
                            </ItemTemplate>
                        </asp:TemplateField>
 
Share this answer
 
v3
Yes,you can use gridview in usercontrol have a look on Full-featured Editable GridView Control[^] and
Create Your Own GridView Control - the ALT.Net's Way[^]
 
Share this answer
 
Hello,

Look at the following links in CP:
Event handling in a Gridview User Control[^]
GridView User control[^]
 
Share this answer
 
U cannot set Datasource in Page. U hav to do it in Usercontrol codebehind page.
put this event in ur user control(ascx.cs)

public void BindGrid(DataTable Dt)
{
if (dt.Rows.Count > 0)
{
grd.DataSource = dt;
grd.DataBind();
}
}
And pass Datatable to usercontrol as this in your aspx code behind page (aspx.cs)
grd.BindGrid(Dt)

This wil bind ur grid
 
Share this answer
 
Comments
Arunachalam Gurusamy 13-Jun-17 16:56pm    
idiotic answer. Question is about gridview usercontrol, read the question again before reply.
Divya RS 23-Aug-17 2:23am    
There is nothing idiotic here.Comments like these will discourage the people. Everyone who answers here tries to help someone.Please be careful in using the words.Yes i will focus much on the question hereafter.
Arunachalam Gurusamy 6-Apr-18 15:22pm    
If the answer was irrelevant then it would be marked as idiotic only. Will you take fever tablet if you suffer from leg pain. Nothing is better than useless answer. If you want to try to help someone irrelevantly then go, tell story on facebook but not here. One should not confuse the questioner, if you dont know then no need to help, who wants irregular answer. I m least bother if my comment discourages or hurts.

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