protected void btnadd_Click(object sender, EventArgs e)
{
int rowIndex = 0;
string selectquery = "select visitorid,VisitorType from VisitorDetails Order By VisitorType";
dt = SqlHelper.Instance.GetTableByQuery(selectquery);
string selectquery1 = "select Id,ArtistsName from MehndiPortraitDetails Order By ArtistsName";
dt1 = SqlHelper.Instance.GetTableByQuery(selectquery1);
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
DropDownList ddlmehndi =
(DropDownList)Gridmehndi.Rows[rowIndex].Cells[0].FindControl("ddlmehndi");
DropDownList ddlArtist =
(DropDownList)Gridmehndi.Rows[rowIndex].Cells[1].FindControl("ddlArtist");
drCurrentRow = dtCurrentTable.NewRow();
TextBox Texttotalamount =
(TextBox)Gridmehndi.Rows[rowIndex].Cells[2].FindControl("txtamount");
dtCurrentTable.Rows[i - 1]["Selected List"] = ddlmehndi.SelectedValue;
dtCurrentTable.Rows[i - 1]["Name of the Artist"] = ddlArtist.SelectedValue;
dtCurrentTable.Rows[i - 1]["Amount Paid"] = Texttotalamount.Text;
rowIndex++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dtCurrentTable;
Gridmehndi.DataSource = dtCurrentTable;
Gridmehndi.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
foreach (GridViewRow gvrow in Gridmehndi.Rows)
{
DropDownList ddlmehndi = (DropDownList)gvrow.FindControl("ddlmehndi");
ddlmehndi.DataTextField = " VisitorType";
ddlmehndi.DataValueField = "Visitorid";
ddlmehndi.DataSource = dt;
ddlmehndi.DataBind();
}
foreach (GridViewRow gvrow1 in Gridmehndi.Rows)
{
DropDownList ddlArtist = (DropDownList)gvrow1.FindControl("ddlArtist");
ddlArtist.DataTextField = "ArtistsName";
ddlArtist.DataValueField = "id";
ddlArtist.DataSource = dt1;
ddlArtist.DataBind();
}
SetPreviousData();
}