Santosh Kumar

Santosh Kumar

  • NA
  • 126
  • 60.3k

Howtoshowrows multiple times inside the footer template when

May 8 2013 5:30 AM
Hi All,
My requirement is to copy multiple rows of grid view into footer row when user checks the check box present inside the grid view and clicks the copy row button out side of the grid.
Actually i have succeeded in copying single row but unable to copy multiple rows.
Please give me any idea or ref links.


My Design is....


<div>
<table style="width: 100%">
<tr>
<td>
<asp:Button ID="btncpyrws" runat="server" Text="CopyRows" Style="color: Blue; width: 100px"
OnClick="btncpyrws_Click" />
 
<asp:Button ID="btndlt" runat="server" Text="Delete" Style="color: Blue; width: 100px"
OnClick="btndlt_Click" OnClientClick="javascript:return dltmsg()" />
 
<asp:Button ID="btncrtrw" runat="server" Text="AddRow" Style="color: Blue; width: 100px"
OnClick="btncrtrw_Click" />
</td>
</tr>
<tr>
<td>
<asp:GridView runat="server" ID="gv" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Username" SortExpression="Username">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Username") %>'></asp:Label>
<asp:HiddenField ID="hdn" runat="server" Value='<%#Eval("Id") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Username") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrtxtunme" runat="server" Text='<%#Eval("Username") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="Password">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Password") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Password") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrtxtpwd" runat="server" Text='<%Eval("Password") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#Eval("FirstName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrfnme" runat="server" Text='<%Eval("FirstName") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrlnme" runat="server" Text='<%Eval("LastName") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrml" runat="server" Text='<%Eval("Email") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phoneno" SortExpression="Phoneno">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Phoneno") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Phoneno") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrphne" runat="server" Text='<%Eval("Phoneno") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="Location">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Location") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Location") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrlctn" runat="server" Text='<%Eval("Location") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Createdby" SortExpression="Location">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Createdby") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Createdby") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ftrcrtdb" runat="server" Text='<%Eval("Createdby") %>'></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Check">
<ItemTemplate>
<asp:CheckBox ID="chkitm" runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Addrecord" runat="server" OnClick="Addrecord_Click" Text="AddRecord" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
</tr>
</table>
</div>


And my Back end code is......


protected void btncpyrws_Click(object sender, EventArgs e)
{
Getrecords flgrd = new Getrecords();
Registrationenitities regist = new Registrationenitities();
foreach (GridViewRow crw in gv.Rows)
{
if (crw.RowType == DataControlRowType.DataRow)
{
CheckBox chbx = (CheckBox)crw.FindControl("chkitm");
if (chbx.Checked)
{
HiddenField hdncp = (HiddenField)crw.FindControl("hdn");
Registrationenitities upentits = new Registrationenitities();
Selectonerec oslct = new Selectonerec();
upentits.Id = int.Parse(hdncp.Value);
var dt = new DataTable();
dt.Columns.Add("Username", typeof(string));
dt.Columns.Add("Password", typeof(string));
dt.Columns.Add("FirstName", typeof(string));
dt.Columns.Add("LastName", typeof(string));
dt.Columns.Add("Email", typeof(string));
dt.Columns.Add("Phoneno", typeof(string));
dt.Columns.Add("Location", typeof(string));
dt.Columns.Add("Createdby", typeof(string));
dt.Columns.Add("Id", typeof(int));
List<Registrationenitities> obj = oslct.Onerecord(upentits);
foreach (Registrationenitities item in obj)
{
DataRow dr = dt.NewRow();
dr["Username"] = item.Username;
dr["Password"] = item.Password;
dr["FirstName"] = item.FirstName;
dr["LastName"] = item.LastName;
dr["Email"] = item.Email;
dr["Phoneno"] = item.Phoneno;
dr["Location"] = item.Location;
dr["Createdby"] = item.Createdby;
dr["Id"] = item.Id;
dt.Rows.Add(dr);
}

for (int i = 0; i < dt.Rows.Count; i++)
{
TextBox ftunme = (TextBox)gv.FooterRow.FindControl("ftrtxtunme");
TextBox ftpwd = (TextBox)gv.FooterRow.FindControl("ftrtxtpwd");
TextBox ftfnme = (TextBox)gv.FooterRow.FindControl("ftrfnme");
TextBox ftlnme = (TextBox)gv.FooterRow.FindControl("ftrlnme");
TextBox fteml = (TextBox)gv.FooterRow.FindControl("ftrml");
TextBox ftphn = (TextBox)gv.FooterRow.FindControl("ftrphne");
TextBox ftlcn = (TextBox)gv.FooterRow.FindControl("ftrlctn");
TextBox ftcrtd = (TextBox)gv.FooterRow.FindControl("ftrcrtdb");
foreach (DataRow dtr in dt.Rows)
{
ftunme.Text = dt.Rows[i]["Username"].ToString();
ftpwd.Text = dt.Rows[i]["Password"].ToString();
ftfnme.Text = dt.Rows[i]["FirstName"].ToString();
ftlnme.Text = dt.Rows[i]["LastName"].ToString();
fteml.Text = dt.Rows[i]["Email"].ToString();
ftphn.Text = dt.Rows[i]["Phoneno"].ToString();
ftlcn.Text = dt.Rows[i]["Location"].ToString();
ftcrtd.Text = dt.Rows[i]["Createdby"].ToString();
gv.FooterRow.Visible = true;
}
}
}
}
}
}