user3721199
user3721199

Reputation: 49

Footer Row Grid VIew

I have footer row in the in Grid View to add the new record. In footer i have three columns (name, phone no & address. When user enters phone no, corresponding details needs to be fetched & bind it to other items in the Footer rows

  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
        ShowFooter="true" onrowdatabound="GridView1_RowDataBound">
    <Columns>
    <asp:TemplateField HeaderText="Name">
     <ItemTemplate>
      <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
      </ItemTemplate>
       <FooterTemplate>
      <asp:TextBox ID="txtName" runat="server" ></asp:TextBox>
     </FooterTemplate>
     </asp:TemplateField>
    <asp:TemplateField HeaderText="Phone">
     <ItemTemplate>
      <asp:Label ID="lblPhone" runat="server" Text='<%# Eval("Phone") %>'></asp:Label>
      </ItemTemplate>
     <FooterTemplate>
      <asp:TextBox ID="txtPhone" runat="server"  ></asp:TextBox>
     </FooterTemplate>
     </asp:TemplateField>
    </Columns>
    </asp:GridView>

Upvotes: 0

Views: 5927

Answers (1)

Humpy
Humpy

Reputation: 2012

You can try something like this..

ASP:

<asp:TemplateField HeaderText="Name">
   <ItemTemplate>
      <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'</asp:Label>
   </ItemTemplate>
   <FooterTemplate>
      <asp:TextBox ID="txtName" runat="server" autopostback="true" OnTextChanged="txtName_TextChanged"></asp:TextBox> //added code here
   </FooterTemplate>
 </asp:TemplateField>

C# Code Behind

protected void txtName_TextChanged(object sender, EventArgs e)
{
    //code here call back fields to other textboxes
}

This hasn't been tested but I have used the onTextChanged before.. just maybe not in a gridivew.. you might need to use..

Textbox txtPhone = GridView1.FooterRow.FindControl("txtPhone");

to find the controls in the footer. Once you find the controls you should be able to populate your textbox with sqldataadapter or datareader.

HOpe this puts you in the right direction!

Upvotes: 1

Related Questions