v venna

v venna

  • NA
  • 72
  • 498

How to Get The Text Box value in Dynamic Grid view

Feb 26 2018 1:28 AM
in Grid view Contains multiple Columns based on Data Same time 3 columns or more
based on search user may enter Data in Grid view and Click on Save Button need to Read the text box value which is created dynamic in Grid view While Am taken as loop but that text box value getting as null 
 
.aspx Code 
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="1500px" DataKeyNames="EmployeeID" BackColor="White" CssClass="table table-hover table-bordered"
runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<HeaderStyle BackColor="#434343" Width="100px" Height="50px" Font-Bold="True" ForeColor="White" />
<FooterStyle Height="21px" CssClass="text-center" />
<%-- <PagerStyle HorizontalAlign="Center" CssClass="gridview" />--%>
<AlternatingRowStyle BackColor="#ffffff" />
</asp:GridView>
</div>
</form>
</body>
</html>
C# Code  
 
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridDynamic();
}
public void GridDynamic()
{
BLL_JPEntitlement jpd = new BLL_JPEntitlement();
DataSet ds = jpd.wfmDeploymentScheduleForEmployee_new();
if (ds.Tables[0].Rows.Count > 0)
{
DataSet dep = jpd.EmployeeDeployeedate();
if (!this.IsPostBack)
{
BoundField bfield = new BoundField();
bfield.HeaderText = "EmployeeID";
bfield.DataField = "EmployeeID";
GridView1.Columns.Add(bfield);
//TemplateField tfield = new TemplateField();
//tfield.HeaderText = "EmployeeName";
//GridView1.Columns.Add(tfield);
bfield = new BoundField();
bfield.HeaderText = "EmployeeName";
bfield.DataField = "EmployeeName";
GridView1.Columns.Add(bfield);
foreach (DataRow item in dep.Tables[0].Rows)
{
bfield = new BoundField();
bfield.HeaderText = item["DeployeeDates"].ToString();
bfield.DataField = item["DeployeeDates"].ToString();
GridView1.Columns.Add(bfield);
}
}
DataSet dss = new DataSet();
DataTable dt = new DataTable();
if (dep.Tables[0].Rows.Count > 0)
{
DataColumn dcol = new DataColumn("EmployeeID", typeof(System.String));
dt.Columns.Add(dcol);
dcol = new DataColumn("EmployeeName", typeof(System.String));
dt.Columns.Add(dcol);
for (int i = 0; i < dep.Tables[0].Rows.Count; i++)
{
dcol = new DataColumn(dep.Tables[0].Rows[i][1].ToString(), typeof(System.String));
dt.Columns.Add(dcol);
y++;
}
}
string tot = "";
for (int nIndex = 0; nIndex < ds.Tables[0].Rows.Count; )
{
DataRow drow = dt.NewRow();
int l = 0;
string s = ds.Tables[0].Rows[nIndex][0].ToString();
//int cancel = 0, rejected = 0, pending = 0, approved = 0;
int ccs = dep.Tables[0].Rows.Count;
int ssd = 0;
int up = 0;
int n1 = 2;
foreach (DataColumn col in dt.Columns)
{
if (l == 0)
{
drow[GridView1.Columns[0].HeaderText] = ds.Tables[0].Rows[nIndex][0];
GridView1.Columns[n1].ItemStyle.Width = 50;
}
else if (l == 1)
{
drow[GridView1.Columns[1].HeaderText] = ds.Tables[0].Rows[nIndex][1];
GridView1.Columns[n1].ItemStyle.Width = 150;
}
else if (s.Equals(ds.Tables[0].Rows[nIndex][0].ToString()))
{
foreach (DataRow item in dep.Tables[0].Rows)
{
string ass = GridView1.Columns[n1].HeaderText;
string assd = dep.Tables[0].Rows[ssd][1].ToString();
if (ass == assd)
{
GridView1.Columns[n1].ItemStyle.Width = 120;
// drow[GridView1.Columns[n1].HeaderText] = dep.Tables[0].Rows[ssd][1];
n1++;
ssd++;
}
}
if (up == 1)
up = 2;
else
nIndex++;
}
else
break;
l++;
if (nIndex == ds.Tables[0].Rows.Count)
break;
}
//drow[GridView1.Columns[y].HeaderText] = tot;
//tot = 0;
dt.Rows.Add(drow);
}
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Visible = true;
}
else
{
// dt.Dispose();
GridView1.DataSource = null;
GridView1.DataBind();
GridView1.Columns.Clear();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
BLL_JPEntitlement jpd = new BLL_JPEntitlement();
DataSet dep = jpd.EmployeeDeployeedate();
int no = 2;
foreach (DataRow item in dep.Tables[0].Rows)
{
TextBox txtCountry = new TextBox();
txtCountry.ID = item["DeployeeDates"].ToString();
txtCountry.Text = "0";
txtCountry.Attributes.Add("runat", "server");
e.Row.Cells[no].Controls.Add(txtCountry);
no++;
}
}
}
protected void ImgDeploymentSave_Click(object sender, ImageClickEventArgs e)
{
BLL_JPEntitlement jpentitlement = new BLL_JPEntitlement();
DataSet Dat= jpentitlement.EmployeeDeployeedate();
//
int RowsCount = Dat.Tables[0].Rows.Count + 2;
int gCount = GridView1.Rows.Count;
foreach (GridViewRow row in GridView1.Rows)
{
foreach (DataRow item in Dat.Tables[0].Rows)
{
string ss = item["DeployeeDates"].ToString();
TextBox tx = (TextBox)row.FindControl(ss);
string sss = tx.Text;
}
}
}
}
 
 
 
 
 
 

Answers (1)