Using jquery i append the gridview values to a table. How to read the dynamic created td values in code behind.
my jquery code is
$(function () {
SetEmptyMessage();
$("[id*=cbSelect]").on("click", function () {
var selected = $('[id$=gvCompanyListing] tr td input[type=checkbox]:checked');
if (selected.length > 0) {
$(selected).each(function () {
var appendRow = $(this).closest('tr').clone(true);
var row = $(this).closest('tr');
$(row).remove();
$("[id$=tblAssigned]").append(appendRow);
});
SetEmptyMessage();
return false;
}
else {
var selected = $('[id$=tblAssigned] tr td input[type=checkbox]:not(:checked)');
if (selected.length > 0) {
$(selected).each(function () {
var appendRow = $(this).closest('tr').clone(true);
var row = $(this).closest('tr');
$(row).remove();
$("[id$=gvCompanyListing]").append(appendRow);
});
}
SetEmptyMessage();
return false;
}
});
});
function SetEmptyMessage() {
if ($('[id$=tblAssigned] td').closest('tr').length == 0) {
//var colspan = $('[id$=gvAssigned] th').length;
//$('[id$=tblAssigned]').append('<tr class="empty"><td colspan=' + colspan + '>No records were found</td></tr>');
} else {
$('[id$=tblAssigned]').find('.empty').remove();
}
if ($('[id$=gvCompanyListing] td').closest('tr').length == 0) {
//var colspan = $('[id$=gvCompanyListing] th').length;
//$('[id$=gvCompanyListing]').append('<tr class="empty"><td colspan=' + colspan + '>No records were found</td></tr>');
} else {
$('[id$=gvCompanyListing]').find('.empty').remove();
}
}
my aspx code is
<asp:GridView ID="gvCompanyListing" runat="server" AutoGenerateColumns="False" ShowHeader="False" GridLines="None" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="cbSelect" CssClass="gridCB" runat="server" ItemStyle-Width="10%"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="client_name" SortExpression="CompanyInfo" ItemStyle-Width="92%" ItemStyle-Height="1px" ControlStyle-CssClass="companyInfo"></asp:BoundField>
</Columns>
</asp:GridView>
<table id="tblAssigned" runat="server">
</table>
And code behind i have,
protected void btnRequestAccess_Click(object sender, EventArgs e)
{
try
{
System.Text.StringBuilder strBuild = new System.Text.StringBuilder();
string strUserName = Session["UserName"].ToString();
int nUserName = strUserName.Length;
int nRemaing = nUserName - 21;
//string strActualName = strUserName.Substring(21, nRemaing);
strBuild.Append("Request to set Clients to Hays user " + strUserName + "\n");
int nval = 0;
for (int i = 0; i <= this.tblAssigned.Rows.Count; i++)
{
HtmlTable td = (HtmlTable)tblAssigned.FindControl("companyInfo");
if (td != null)
{
strBuild.Append(tblAssigned.Items[i].Text.ToString()+"\n")
nval = nval + 1;
}
}
}
}
How to get the tblAssigned value as text in code behind.what is the mistake i done?