locked
Date in Child Gridview RRS feed

  • Question

  • User-1499457942 posted

    Hi

      How to get Date in Child Gridview row

    Thanks

    Sunday, November 11, 2018 1:22 PM

All replies

  • User-1716253493 posted

    Please elaborate your question. You can post question with your code snippet or some description what you have and what you want.

    Such as, from where you want to get the date

    Monday, November 12, 2018 1:47 AM
  • User61956409 posted

    Hi JagjitSingh,

    How to get Date in Child Gridview row

    If you'd like to get Date from child GridView row by user selected a row, you can achieve it in OnRowCommand event of child GridView.

    Selected Date:
    <asp:Label ID="lbldate" runat="server" Text=""></asp:Label>
    <br />
    <br />
    <br />
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:BoundField HeaderText="Id" DataField="Id" />
            <asp:TemplateField HeaderText="Child Data">
                <ItemTemplate>
                    <asp:GridView ID="ChildGrid" runat="server" AutoGenerateColumns="false" OnRowCommand="ChildGrid_RowCommand">
                        <Columns>
                            <asp:BoundField HeaderText="CId" DataField="CId" />
                            <asp:BoundField HeaderText="CDate" DataField="CDate" />
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:Button ID="btngetdate" runat="server" Text="Get Date" CommandName="getdate" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    protected void ChildGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName== "getdate")
        {
            GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
            lbldate.Text = row.Cells[1].Text;
        }
    }

    Test Result:

    Besides, if possible, you can loop trough child GridView rows and get date from each row via OnRowDataBound event.

    With Regards,

    Fei Han

    Monday, November 12, 2018 5:50 AM
  • User-1499457942 posted

    Hi oned_gk

     I have below code . I want calendar so that user can select date .

                    <asp:GridView ID="gvwEmployee" OnPreRender="gvwEmployee_PreRender" runat="server"  CssClass="table table-bordered table-striped"
                     AutoGenerateColumns="false" OnRowCommand="gvwEmployee_RowCommand" OnRowDataBound="gvwEmployee_RowDataBound"
                    BorderWidth="1px"  BorderStyle="None" BorderColor="#DEBA84" ClientIDMode="Static"
                    EmptyDataText="No Records Found!" EmptyDataRowStyle-ForeColor="Red" EmptyDataRowStyle-CssClass ="gvEmpty" >
                    
    
                     />
    
                    <Columns>
                        <asp:templatefield headertext="Action">
                            <itemtemplate>
                                <asp:linkbutton id="btnedit"  tooltip="update record" CommandName="EditRow" causesvalidation="false" runat="server" cssclass="clslnkbutton"/> 
                            </itemtemplate>
                        </asp:templatefield>
    
                        <asp:templatefield headertext="Emp.Code">
                            <itemtemplate>
                                <asp:label runat="server" id="lblcode" text='<%#Eval("EmployeeId") %>'></asp:label>
                            </itemtemplate>
                        </asp:templatefield>
                        <asp:templatefield headertext="Name">
                            <itemtemplate>
                                <asp:label runat="server" id="lblFullName" text='<%#Eval("FullName") %>'></asp:label>
                            </itemtemplate>
                        </asp:templatefield>
                                            
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:Button ID="Button1" runat="server" Text="Incentive History" CommandName='<%#Eval("EmployeeId") %>' CommandArgument='<%#  
                                    Container.DataItemIndex%>' />
                                    <asp:GridView ID="gvwDetails" runat="server" AutoGenerateColumns="false"  CssClass="table table-bordered table-striped">
                                        <Columns>
                                            <asp:TemplateField HeaderText="EmployeeId" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblEmployeeIdChild" Text='<%# Eval("EmployeeId") %>' runat="server"></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField ItemStyle-Width="100px" HeaderText="Amount">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblAmountChild" runat="server" Text='<%# Eval("BaseAmount")%>'></asp:Label>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtAmount_Child" runat="server" Text='<%# Bind("BaseAmount")%>'></asp:TextBox>
                                                </EditItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText = "Duration">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblPeriodChild" runat="server" Text='<%# Eval("Incentive_Duration") %>' Visible = "false" />
                                                    <asp:DropDownList ID="ddl_PeriodChild" runat="server">
                                                    </asp:DropDownList>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:ButtonField CommandName="Edit" Text="Edit" />
                                            <asp:ButtonField CommandName="Delete" Text="Delete" />
                                            <asp:ButtonField CommandName="Update" Text="Update" />
                                        </Columns>
                                    </asp:GridView>
                                <%--</asp:Panel>--%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                    </Columns>
                    </asp:GridView>

    Thanks

    Monday, November 12, 2018 6:39 AM
  • User-1716253493 posted

    Simply use textbox, bind the text property to the datefield

    Add jquery datepicker to the page, use class as selector instead of id

    <asp:textbox id="thedate" cssclass="datepicker" text='<%# Bind("datecolumn") %>' />

    If you use code behind such as editing or updating event is almost no deferent between parent or child. It's similar.

    <script>
      $(function() {
        $(".datepicker").datepicker();
      } );
    </script>

    https://jqueryui.com/datepicker/

    Tuesday, November 13, 2018 1:37 AM
  • User61956409 posted

    Hi JagjitSingh,

    JagjitSingh

    I want calendar so that user can select date

    You can try to use ajaxToolkit:CalendarExtender to implement date-picking functionality.

    <asp:TemplateField>
        <ItemTemplate>
            <asp:Label ID="lbldate" runat="server" Text='<%#Eval("datefiled") %>'></asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtdate" runat="server" Text='<%#Eval("datefiled") %>'></asp:TextBox>
            <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtdate" SelectedDate='<%#Eval("datefiled") %>' />
        </EditItemTemplate>
    </asp:TemplateField>

    With Regards,

    Fei Han

    Tuesday, November 13, 2018 3:27 AM