locked
how to use update pannel in gridview control RRS feed

  • Question

  • User-644330731 posted

    dear all,

     how can i use update pannel in gridview control . below is my code

    <td colspan="2" align="center">
                        <asp:GridView runat="server" ID="grd1" AutoGenerateColumns="false" OnRowCommand="Gird1_RowCommand">
                            <Columns>
                                <asp:TemplateField HeaderText="country id">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblid" Text='<%#Eval("COUNTRYID") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Country Name">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblcountry" Text='<%#Eval("COUNTRY_NAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="F Name">
                                    <ItemTemplate>
                                        <asp:Label ID="fname" runat="server" Text='<%#Eval("FNAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="L Name">
                                    <ItemTemplate>
                                        <asp:Label ID="Lname" runat="server" Text='<%#Eval("LNAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Select">
                                    <ItemTemplate>
                                        <asp:LinkButton runat="server" CommandArgument='<%#Eval("REGID") %>' Text="select me"
                                            CommandName="select"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </td>
    
    public  void Gird1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
    
            if (e.CommandName == "select")
            {
                GridViewRow gr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                Label l = (Label)gr.FindControl("lblcountry");
                Label FNAME=(Label)gr.FindControl("FNAME");
                Label LNAME = (Label)gr.FindControl("LNAME");
                txtFname.Text = FNAME.Text; txtLname.Text = LNAME.Text;
    
    
            }
        }

    now i want when i click on "select" button , without postback values should be filled inside controls... 

    how can i use this?

    Tuesday, May 6, 2014 3:48 AM

Answers

  • User-417640953 posted

    now i want when i click on "select" button , without postback values should be filled inside controls... 

    Hi priya15_pate,

    Thanks for the post.

    As known that without any postback your page will not update in asp.net.

    So I think you can do a partial postback using the updatepanel wrap your gridview control like below.

     <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                <Triggers><asp:AsyncPostBackTrigger ControlID="grd1" EventName="RowCommand" /></Triggers>
                <ContentTemplate>
    
                       <asp:GridView runat="server" ID="grd1" AutoGenerateColumns="false" OnRowCommand="Gird1_RowCommand">
                            <Columns>
                                <asp:TemplateField HeaderText="country id">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblid" Text='<%#Eval("COUNTRYID") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Country Name">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblcountry" Text='<%#Eval("COUNTRY_NAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="F Name">
                                    <ItemTemplate>
                                        <asp:Label ID="fname" runat="server" Text='<%#Eval("FNAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="L Name">
                                    <ItemTemplate>
                                        <asp:Label ID="Lname" runat="server" Text='<%#Eval("LNAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Select">
                                    <ItemTemplate>
                                        <asp:LinkButton runat="server" CommandArgument='<%#Eval("REGID") %>' Text="select me"
                                            CommandName="select"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                </ContentTemplate>
    
            </asp:UpdatePanel>

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2014 11:20 PM

All replies

  • User-736011398 posted
    <asp:UpdatePanel ID="UP" runat="server">
    <ContentTemplate>
       //GridView
    </ContentTemplate>
    </asp:UpdatePanel>

    And do not forgot to put script manager in same page.

    Or you can put same for perticular control too.

    Tuesday, May 6, 2014 3:57 AM
  • User-417640953 posted

    now i want when i click on "select" button , without postback values should be filled inside controls... 

    Hi priya15_pate,

    Thanks for the post.

    As known that without any postback your page will not update in asp.net.

    So I think you can do a partial postback using the updatepanel wrap your gridview control like below.

     <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                <Triggers><asp:AsyncPostBackTrigger ControlID="grd1" EventName="RowCommand" /></Triggers>
                <ContentTemplate>
    
                       <asp:GridView runat="server" ID="grd1" AutoGenerateColumns="false" OnRowCommand="Gird1_RowCommand">
                            <Columns>
                                <asp:TemplateField HeaderText="country id">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblid" Text='<%#Eval("COUNTRYID") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Country Name">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lblcountry" Text='<%#Eval("COUNTRY_NAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="F Name">
                                    <ItemTemplate>
                                        <asp:Label ID="fname" runat="server" Text='<%#Eval("FNAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="L Name">
                                    <ItemTemplate>
                                        <asp:Label ID="Lname" runat="server" Text='<%#Eval("LNAME") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Select">
                                    <ItemTemplate>
                                        <asp:LinkButton runat="server" CommandArgument='<%#Eval("REGID") %>' Text="select me"
                                            CommandName="select"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                </ContentTemplate>
    
            </asp:UpdatePanel>

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2014 11:20 PM