Add info using textbox into gridview after retrieving data from database C# - c#

I'm retrieving data from database into the grid for 5 column, there is another 3 columns beside that which I want to fill in using textbox input (using different button).
How to fetch the input from the textbox into the grid after I retrieve the data from database?
Here is the front looks like:
Here is the coding:
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="BNE No: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="BNE No: "></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Search From Database" />
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:Button ID="Button3" runat="server" Text="Insert to Grid" OnClick="Button3_Click" />
<br />
<%--<asp:Table ID="Table1" runat="server">
</asp:Table>--%>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="BNE No">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#Bind("BNENo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ECN No">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%#Bind("KVNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rec Date">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%#Bind("ReceivedDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Issued Date">
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#Bind("IssuedDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%#Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location">
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text=''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Time">
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text=''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text=''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
Here is the behind code where I use to retrieve the data by using button 1
protected void Button1_Click(object sender, EventArgs e)//this Button use To call multiple data from database named tblBNE into GridView
{
count = 0;
con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT [BNENo],[KVNo],[ReceivedDate],[IssuedDate],[Status] FROM [tblBNE] where BNENo='" + TextBox1.Text + "' or BNENo='" + TextBox2.Text + "' ";
cmd.ExecuteNonQuery();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
count = Convert.ToInt32(dt.Rows.Count.ToString());
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
if (count == 0)
{
Label3.Text = "record not found";
}
}
So, I want to use button 3 = insert to grid to fill into label9 to 11 using textbox3 to 5. How can I do that?
Thank you in advance :)

Related

Get text box value from grid view Header

I have grid with text box for filter data on header.I have button outside the grid.I am using this gridview for filtering the grid by some columns. When I click on button I want to get value from text box and dropdownlist on codebehind.cs, below is my webform.aspx code of gridview,
<asp:Button ID="btngetLocationDate" runat="server" Text="Get Filtered Data" OnClick="getTextBoxValue"></asp:Button>
<asp:GridView ID="TrackerGrid" runat="server" BackColor="#CCCCCC" AllowPaging="True" AutoGenerateColumns="false">
<AlternatingRowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
<asp:TemplateField HeaderText="User ID" SortExpression="User ID">
<ItemTemplate>
<asp:Label ID="lbluserid" runat="server" Text='<%# Eval("User ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<HeaderTemplate>
Full Name:
<asp:DropDownList ID="ddlfullName" runat="server" AutoPostBack="true" OnSelectedIndexChanged="onselectDropdown">
<asp:ListItem Text="ALL" Value="ALL" Selected="True"></asp:ListItem>
</asp:DropDownList>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%# Eval("Full Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile Number">
<HeaderTemplate>
Mobile Number:
<asp:TextBox ID="txtMobilenumber" runat="server" AutoPostBack="true"></asp:TextBox>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblmobile" runat="server" Text='<%# Eval("Mobile Phone") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email Address">
<HeaderTemplate>
Email Id:
<asp:TextBox ID="txtemail" runat="server" AutoPostBack="true"></asp:TextBox>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblemail" runat="server" Text='<%# Eval("Email ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Longitude">
<HeaderTemplate>
<asp:Label ID="lbllng" runat="server" Text="Longitude"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbllongi" runat="server" Text='<%# Eval("Longitude") %>' Width="70"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lattitude">
<HeaderTemplate>
<asp:Label ID="lbllat" runat="server" Text="Lattitude"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbllatti" runat="server" Text='<%# Eval("Lattitude") %>' Width="70"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Activated On">
<HeaderTemplate>
<asp:Label ID="lbldevices" runat="server" Text="Activated On"></asp:Label></br>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lbldevice" runat="server" Text='<%# Eval("Activated On") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location DateTime" SortExpression="Location DateTime">
<HeaderTemplate>
<asp:Label ID="Label1" runat="server" Text="Location DateTime"></asp:Label></br>
<asp:Label ID="lblStartDate" runat="server" AssociatedControlID="txtStartDate" Text="Start Date"></asp:Label>
<asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
<cc1:calendarextender id="CalendarStartDate" runat="server" format="dd/MM/yyyy" targetcontrolid="txtStartDate" popupbuttonid="imgPopup1"></cc1:calendarextender>
<asp:ImageButton ID="imgPopup1" runat="server" ImageUrl="https://cdn4.iconfinder.com/data/icons/small-n-flat/24/calendar-alt-512.png" Height="20px" Width="30px" />
</br>
<asp:Label ID="lblEndDate" runat="server" Text="End Date" AssociatedControlID="txtEndDate"></asp:Label>
<asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>
<cc1:calendarextender id="CalendarEndDate" runat="server" format="dd/MM/yyyy" targetcontrolid="txtEndDate" popupbuttonid="imgPopup2"></cc1:calendarextender>
<asp:ImageButton ID="imgPopup2" runat="server" ImageUrl="https://cdn4.iconfinder.com/data/icons/small-n-flat/24/calendar-alt-512.png" Height="20px" Width="30px" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDatetime" runat="server" Text='<%# Eval("Location DateTime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and I am getting texbox value in codebehind code.
protected void getTextBoxValue(object sender, EventArgs e)
{
DropDownList ddlfullname = (TrackerGrid.HeaderRow.FindControl("ddlfullName") as DropDownList);
string selectedValue = ddlfullname.SelectedItem.Text;
TextBox mobilenumber = (TrackerGrid.HeaderRow.FindControl("txtMobilenumber") as TextBox);
string mobile = mobilenumber.Text;
TextBox email = TrackerGrid.HeaderRow.FindControl("txtemail") as TextBox;
string emailid = email.Text;
TextBox staloc = TrackerGrid.HeaderRow.FindControl("txtStartDate") as TextBox;
string startlocatdate = staloc.Text;
TextBox endloc = TrackerGrid.HeaderRow.FindControl("txtEndDate") as TextBox;
string endlocadate = endloc.Text;
}
I am getting empty value when I debugging this code.I think my code is correct but how i am not getting value of textboxes, i don't understand. Please help me for solving my issue.
Thanks in advance.
You probably did not wrap the DataBind() of the Gridview inside an IspostBack check. If you do not then the values will be rested by the DataBind instead of being saved with ViewState.
protected void Page_Load(object sender, EventArgs e)
{
//not here
TrackerGrid.DataSource = source;
TrackerGrid.DataBind();
if (IsPostBack == false)
{
//but inside an ispostback check
TrackerGrid.DataSource = source;
TrackerGrid.DataBind();
}
}

Use child footer row to add new record to a nested gridview

I have a nested grid views:
<asp:GridView ID="gvRequisitions" runat="server" AutoGenerateColumns="false"
DataKeyNames="PurchaseRequisitionID" OnRowDataBound="OnRowDataBound" ShowFooter="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor:pointer" src="../images/plus.png" width="12" height="12" />
<asp:Panel ID="pnlItems" runat="server" Style="display: none">
<asp:GridView ID="gvItems" runat="server" AutoGenerateColumns="false" ShowFooter="true"
OnRowDataBound="gvItems_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblItemID" runat="server" Text='<%# Eval("ItemID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAddItem" runat="server" OnClick="addItem" Text="add" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Code">
<ItemTemplate>
<asp:Label ID="lblItemCode" runat="server" Text='<%# Eval("ItemCode") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtItemCode" runat="server" Visible="true" Width="100"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>'
Width="225"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtDescription" runat="server" Width="225"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date req.">
<ItemTemplate>
<asp:Label ID="lblDateRequired" runat="server" Text='<%# Eval("DateRequired") %>'
Width="75"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtDateRequired" runat="server" Width="75"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Measure">
<ItemTemplate>
<asp:Label ID="lblMeasure" runat="server" Text='<%# Eval("MeasureID") %>'
Width="120" ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlMeasure" runat="server" Width="120"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:Label ID="lblQuantity" runat="server" Text='<%# Eval("Quantity") %>' Width="75"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtQuantity" runat="server" Width="75"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cost">
<ItemTemplate>
<asp:Label ID="lblCostPerUnit" runat="server" Text='<%# Eval("CostPerUnit") %>' Width="75"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtCostPerUnit" runat="server" Width="75"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" Text='<%# Eval("Total") %>' Width="120"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>No Items For this Requisition</EmptyDataTemplate>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblPurchaseRequisitionID" runat="server" Text='<%# Eval("PurchaseRequisitionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAddReq" runat="server" Text="Add" OnClick="addPurreq" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Requested By">
<ItemTemplate>
<asp:Label ID="lblRequestor" runat="server" Text='<%# Eval("Requestor") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlRequestor" runat="server" Width="200"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department">
<ItemTemplate>
<asp:Label ID="lblDepartmentID" runat="server" Text='<%# Eval("DepartmentID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlDepartment" runat="server" Width="200" ></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budget">
<ItemTemplate>
<asp:Label ID="lblBudgetID" runat="server" Text='<%# Eval("BudgetID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlBudget" runat="server" Width="200"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Supplier">
<ItemTemplate>
<asp:Label ID="lblSupplierID" runat="server" Text='<%# Eval("SupplierID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlSupplier" runat="server" Width="200"></asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Created">
<ItemTemplate>
<asp:Label ID="lblDateCreated" runat="server" Text='<%# Eval("DateCreated","{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In code behind I have:
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
string purchaseRequisitionID = gvRequisitions.DataKeys[e.Row.RowIndex].Value.ToString();
GridView gvItems = (GridView)e.Row.FindControl("gvItems");
// new code to send reference to gvItems_RowDataBound
gvItems.RowDataBound += new GridViewRowEventHandler(gvItems_RowDataBound);
int id = Convert.ToInt32(purchaseRequisitionID);
using (SqlConnection conn = new SqlConnection(constr))
{
using(SqlCommand comm = new SqlCommand("procItems_CRUD"))
{
comm.Parameters.AddWithValue("#Action", "SELECT");
comm.Parameters.AddWithValue("#ID", id);
using(SqlDataAdapter sda = new SqlDataAdapter())
{
comm.CommandType = CommandType.StoredProcedure;
comm.Connection = conn;
sda.SelectCommand = comm;
using(DataTable dt = new DataTable())
{
sda.Fill(dt);
gvItems.DataSource = dt;
gvItems.DataBind();
}
}
}
}
}
}
And:
protected void gvItems_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlMeasure = e.Row.FindControl("ddlMeasure") as DropDownList;
if(ddlMeasure == null)
{
}
}
}
But I cannot see the drop down list as it returns a null value (as I know it is not a DataRow) but how can I see the footer row and the elements in footer row so that I can add another Item to the order/populate DropDownList etc.
Have been trying to sort this for some time and cannot find a working solution so any pointer(s) will be very much appreciated.
You need to use DataControlRowType.Footer.
protected void gvItems_RowDataBound(object sender, GridViewRowEventArgs e)
{
//check if the row is a footer row
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList ddlMeasure = e.Row.FindControl("ddlMeasure") as DropDownList;
if (ddlMeasure != null)
{
ddlMeasure.Items.Insert(0, new ListItem("DLL Found!", "-1"));
}
}
}

on add button click data insert twice

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyManageConnectionString"].ToString());
string InstituteId = HttpContext.Current.Request.Cookies["InstituteId"].Value;
protected void Page_Load(object sender, EventArgs e)
{
((Label)Master.FindControl("lblPageName")).Text = "Employee List";
((Label)Master.FindControl("lblPageName")).ForeColor = System.Drawing.Color.Black;
((Label)Master.FindControl("lblPageName1")).Text = " Employee List";
if (Request.Cookies["InstituteId"] == null)
{
string OriginalUrl = HttpContext.Current.Request.RawUrl;
string LoginPageUrl = "INlogin.aspx";
HttpContext.Current.Response.Redirect(String.Format("{0}?R={1}", LoginPageUrl, OriginalUrl));
}
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
string strQuery = "select * from tblEmployee where InstituteId=#InstituteId";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.AddWithValue("#InstituteId", InstituteId);
gvEmpList.DataSource = GetData(cmd);
gvEmpList.DataBind();
}
private DataTable GetData(SqlCommand cmd)
{
DataTable dt = new DataTable();
//SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
protected void btnAdd_Click(object sender, EventArgs e)
{
string ActivationCode = Guid.NewGuid().ToString();
string txtEmployeeName = ((TextBox)gvEmpList.FooterRow.FindControl("txtEmployeeName")).Text;
string txtEmployeeAddress = ((TextBox)gvEmpList.FooterRow.FindControl("txtEmployeeAddress")).Text;
string txtEmployeeEmailId = ((TextBox)gvEmpList.FooterRow.FindControl("txtEmployeeEmailId")).Text;
string txtMobile = ((TextBox)gvEmpList.FooterRow.FindControl("txtMobile")).Text;
string txtBirthDate = ((TextBox)gvEmpList.FooterRow.FindControl("txtBirthDate")).Text;
string txtdateOfJoining = ((TextBox)gvEmpList.FooterRow.FindControl("txtdateOfJoining")).Text;
string txtExperiance = ((TextBox)gvEmpList.FooterRow.FindControl("txtExperiance")).Text;
string txtLastSchoolDetails = ((TextBox)gvEmpList.FooterRow.FindControl("txtLastSchoolDetails")).Text;
string txtSalaryDetails = ((TextBox)gvEmpList.FooterRow.FindControl("txtSalaryDetails")).Text;
bool chkmerriageStatus = ((CheckBox)gvEmpList.FooterRow.FindControl("chkmerriageStatus")).Checked;
string txtNationality = ((TextBox)gvEmpList.FooterRow.FindControl("txtNationality")).Text;
try
{
//SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
//con.Open();
//cmd.Connection = con;
cmd.CommandText = "INSERT INTO tblEmployee (InstituteId, EmployeeName, EmployeeAddress, EmployeeEmailId, Mobile, BirthDate, dateOfJoining, Experiance, LastSchoolDetails, SalaryDetails, merriageStatus, Nationality, ActivationCode, ActivationStatus, Password) VALUES (#InstituteId, #EmployeeName, #EmployeeAddress, #EmployeeEmailId, #Mobile, #BirthDate, #dateOfJoining, #Experiance, #LastSchoolDetails, #SalaryDetails, #merriageStatus, #Nationality, #ActivationCode, #ActivationStatus, #Password);" + "select * from tblEmployee where InstituteId=#InstituteId";
cmd.Parameters.AddWithValue("#InstituteId", InstituteId);
cmd.Parameters.AddWithValue("#EmployeeName", txtEmployeeName);
cmd.Parameters.AddWithValue("#EmployeeAddress", txtEmployeeAddress);
cmd.Parameters.AddWithValue("#EmployeeEmailId", txtEmployeeEmailId);
cmd.Parameters.AddWithValue("#Mobile", txtMobile);
cmd.Parameters.AddWithValue("#BirthDate", txtBirthDate);
cmd.Parameters.AddWithValue("#dateOfJoining", txtdateOfJoining);
cmd.Parameters.AddWithValue("#Experiance", txtExperiance);
cmd.Parameters.AddWithValue("#LastSchoolDetails", txtLastSchoolDetails);
cmd.Parameters.AddWithValue("#SalaryDetails", txtSalaryDetails);
cmd.Parameters.AddWithValue("#merriageStatus", chkmerriageStatus);
cmd.Parameters.AddWithValue("#Nationality", txtNationality);
cmd.Parameters.AddWithValue("#ActivationCode", ActivationCode);
cmd.Parameters.AddWithValue("#ActivationStatus", false);
string GTPassword = System.Web.Security.Membership.GeneratePassword(8, 3);
cmd.Parameters.AddWithValue("#Password", GTPassword);
//int result = cmd.ExecuteNonQuery();
//con.Close();
//if (result == 1)
//{
// sendActivation(ActivationCode, txtEmployeeName, txtEmployeeEmailId);
// Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Registration Successfull')", true);
//}
//else {
// Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Registration Fail')", true);
//}
gvEmpList.DataSource = GetData(cmd);
gvEmpList.DataBind();
//BindData();
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
When the add button is clicked btnAdd_click inserts data twice. Also I am not getting any exception errors in btnadd_click code.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="dvGrid" style="overflow-x: scroll; Overflow: scroll;">
<asp:UpdatePanel ID="upEmployeeList" runat="server">
<ContentTemplate>
<asp:GridView Width="100%" ID="gvEmpList" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeId" CssClass="gvmydatagrid" PagerStyle-CssClass="gvpager" HeaderStyle-CssClass="gvheader" RowStyle-CssClass="gvrows" ShowFooter="True" OnPageIndexChanging="gvEmpList_PageIndexChanging" OnRowEditing="gvEmpList_RowEditing" OnRowUpdating="gvEmpList_RowUpdating" OnRowCancelingEdit="gvEmpList_RowCancelingEdit" AllowPaging="True" PageSize="25">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkRemove" runat="server"
CommandArgument='<%# Eval("EmployeeId")%>'
OnClientClick="return confirm('Do you want to delete?')"
Text="Delete" OnClick="lnkRemove_Click"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
<asp:TemplateField HeaderText="EmployeeId" InsertVisible="False" SortExpression="EmployeeId">
<EditItemTemplate>
<asp:Label ID="lblEmployeeId" runat="server" Text='<%# Eval("EmployeeId") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblEmployeeId" runat="server" Text='<%# Bind("EmployeeId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="InstituteId" SortExpression="InstituteId">
<EditItemTemplate>
<asp:Label ID="txtInstituteId" runat="server" Text='<%# Bind("InstituteId") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblInstituteId" runat="server" Text='<%# Bind("InstituteId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>--%>
<asp:TemplateField HeaderText="EmployeeName" SortExpression="EmployeeName">
<EditItemTemplate>
<asp:TextBox ID="txtEmployeeName" runat="server" Text='<%# Bind("EmployeeName") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtEmployeeName" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblEmployeeName" runat="server" Text='<%# Bind("EmployeeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmployeeAddress" SortExpression="EmployeeAddress">
<EditItemTemplate>
<asp:TextBox ID="txtEmployeeAddress" runat="server" Text='<%# Bind("EmployeeAddress") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtEmployeeAddress" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblEmployeeAddress" runat="server" Text='<%# Bind("EmployeeAddress") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmployeeEmailId" SortExpression="EmployeeEmailId">
<EditItemTemplate>
<asp:TextBox ID="txtEmployeeEmailId" runat="server" Text='<%# Bind("EmployeeEmailId") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtEmployeeEmailId" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblEmployeeEmailId" runat="server" Text='<%# Bind("EmployeeEmailId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile" SortExpression="Mobile">
<EditItemTemplate>
<asp:TextBox ID="txtMobile" runat="server" Text='<%# Bind("Mobile") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblMobile" runat="server" Text='<%# Bind("Mobile") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BirthDate" SortExpression="BirthDate">
<EditItemTemplate>
<asp:TextBox ID="txtBirthDate" runat="server" Text='<%# Bind("BirthDate") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtBirthDate" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblBirthDate" runat="server" Text='<%# Bind("BirthDate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="dateOfJoining" SortExpression="dateOfJoining">
<EditItemTemplate>
<asp:TextBox ID="txtdateOfJoining" runat="server" Text='<%# Bind("dateOfJoining") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtdateOfJoining" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lbldateOfJoining" runat="server" Text='<%# Bind("dateOfJoining") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Experiance" SortExpression="Experiance">
<EditItemTemplate>
<asp:TextBox ID="txtExperiance" runat="server" Text='<%# Bind("Experiance") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtExperiance" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblExperiance" runat="server" Text='<%# Bind("Experiance") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastSchoolDetails" SortExpression="LastSchoolDetails">
<EditItemTemplate>
<asp:TextBox ID="txtLastSchoolDetails" runat="server" Text='<%# Bind("LastSchoolDetails") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtLastSchoolDetails" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblLastSchoolDetails" runat="server" Text='<%# Bind("LastSchoolDetails") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SalaryDetails" SortExpression="SalaryDetails">
<EditItemTemplate>
<asp:TextBox ID="txtSalaryDetails" runat="server" Text='<%# Bind("SalaryDetails") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtSalaryDetails" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblSalaryDetails" runat="server" Text='<%# Bind("SalaryDetails") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="merriageStatus" SortExpression="merriageStatus">
<EditItemTemplate>
<asp:CheckBox ID="chkmerriageStatus" runat="server" Checked='<%# Bind("merriageStatus") %>' />
</EditItemTemplate>
<FooterTemplate>
<asp:CheckBox ID="chkmerriageStatus" runat="server"></asp:CheckBox>
</FooterTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkmerriageStatus" runat="server" Checked='<%# Bind("merriageStatus") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Nationality" SortExpression="Nationality">
<EditItemTemplate>
<asp:TextBox ID="txtNationality" runat="server" Text='<%# Bind("Nationality") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNationality" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblNationality" runat="server" Text='<%# Bind("Nationality") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="Password">
<EditItemTemplate>
<asp:TextBox ID="txtPassword" runat="server" Text='<%# Bind("Password") %>'></asp:TextBox>
</EditItemTemplate>
<%--<FooterTemplate>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
</FooterTemplate>--%>
<ItemTemplate>
<asp:Label ID="lblPassword" runat="server" Text='<%# Bind("Password") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="gvheader" />
<PagerStyle CssClass="gvpager" />
<RowStyle CssClass="gvrows" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvEmpList" />
</Triggers>
</asp:UpdatePanel>
</div>
When I click on add button, footer item data will insert into my database but is insert twice. It is in debug mode and jumping around everywhere.
it show "The process or thread has changed since last step."
You are sending the insert command again by calling gvEmpList.DataSource = GetData(cmd); inside btnAdd_Click. Please check it. The cmd object inside btnAdd_Click is an insert command.
Remove following code from btnAdd_Click
gvEmpList.DataSource = GetData(cmd);
gvEmpList.DataBind();
And call following method
BindData();

Problems with nested gridview

I am trying to design gridview inside gridview with insert update and delete but in this i cant insert record. Can anyone Help?
Here is database table
1) tbl_SShow(ShowTimeId{P-Auto inc.},TheatreId,MovieId,FromDate,ToDate)
2) tbl_Show(ShowID{P-Auto inc.},ShowTime,Silver,Gold, Platinum,ShowTimeId)
3) tbl_Theatre(TheatreId{P-Auto inc.}, TName, Taddress)
and here is aspx page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script language=javascript type="text/javascript">
function expandcollapse(obj,row)
{
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display == "none")
{
div.style.display = "block";
if (row == 'alt')
{
img.src = "minus.gif";
}
else
{
img.src = "minus.gif";
}
img.alt = "Close to view other Customers";
}
else
{
div.style.display = "none";
if (row == 'alt')
{
img.src = "plus.gif";
}
else
{
img.src = "plus.gif";
}
img.alt = "Expand to show Orders";
}
}
</script>
</head>
<body>
<form id="AddEventForm" runat="server">
<ul id="tabsmenu1" class="tabsmenu">
<li class="active">Add Show Time</li>
</ul>
<div class="form">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="#f1f1f1"
AutoGenerateColumns=false DataSourceID="SqlDataSource1" DataKeyNames="MovieID"
GridLines=None OnRowDataBound="GridView1_RowDataBound"
OnRowCommand = "GridView1_RowCommand" OnRowUpdating = "GridView1_RowUpdating" BorderStyle=Outset
OnRowDeleting = "GridView1_RowDeleting" OnRowDeleted = "GridView1_RowDeleted"
OnRowUpdated = "GridView1_RowUpdated" AllowSorting=true
Width="80%" >
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White"/>
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:expandcollapse('div<%# Eval("ShowTimeId") %>', 'one');">
<img id="imgdiv<%# Eval("ShowTimeId") %>" alt="Click to show/hide Orders for Customer <%# Eval("ShowTimeId") %>" width="9px" border="0" src="../images/plus.gif"/>
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Theatre Id" SortExpression="TheatreId">
<ItemTemplate>
<asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Theatre Id" SortExpression="TheatreId">
<ItemTemplate>
<asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlTheatre" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="1">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Movie Id" SortExpression="MovieId">
<ItemTemplate><%# Eval("MovieId")%></ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlMovie" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="2">
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="ddlMovie" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="2">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="From Date" SortExpression="FromDate">
<ItemTemplate><%# Eval("FromDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFromDate" Text='<%# Eval("FromDate") %>' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
</asp:CalendarExtender>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtFromDate" Text='' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
</asp:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To Date" SortExpression="ToDate">
<ItemTemplate><%# Eval("ToDate")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtToDate" Text='<%# Eval("ToDate") %>' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
</asp:CalendarExtender>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtToDate" Text='' runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
<asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
</asp:CalendarExtender>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteShow" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddShow" CommandName="AddShow" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("ShowTimeId") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >
<asp:GridView ID="GridView2" AllowPaging="True" AllowSorting="true" BackColor="White" Width=100% Font-Size=X-Small
AutoGenerateColumns="false" Font-Names="Verdana" DataKeyNames="ShowTimeId" runat="server" ShowFooter="true"
OnPageIndexChanging="GridView2_PageIndexChanging" OnRowUpdating = "GridView2_RowUpdating" CssClass="Gridview"
OnRowCommand = "GridView2_RowCommand" OnRowEditing = "GridView2_RowEditing" GridLines=None
OnRowUpdated = "GridView2_RowUpdated" OnRowCancelingEdit = "GridView2_CancelingEdit" OnRowDataBound = "GridView2_RowDataBound"
OnRowDeleting = "GridView2_RowDeleting" OnRowDeleted = "GridView2_RowDeleted" OnSorting = "GridView2_Sorting"
BorderStyle=Double BorderColor="#0083C1">
<RowStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#0083C1" ForeColor="White"/>
<FooterStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Show ID" SortExpression="ShowID">
<ItemTemplate>
<asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ShowTime" SortExpression="ShowTime">
<ItemTemplate><%# Eval("ShowTime")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtShowTime" Text='<%# Eval("ShowTime")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtShowTime" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Silver" SortExpression="Silver">
<ItemTemplate><%# Eval("Silver")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtSilver" Text='<%# Eval("Silver")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtSilver" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gold" SortExpression="Gold">
<ItemTemplate><%# Eval("Gold")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtGold" Text='<%# Eval("Gold")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtGold" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Platinum" SortExpression="Platinum">
<ItemTemplate><%# Eval("Platinum")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPlatinum" Text='<%# Eval("Platinum")%>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPlatinum" Text='' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="linkDeleteCust" CommandName="Delete" runat="server">Delete</asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkAddOrder" CommandName="AddShow" runat="server">Add</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Event_MovieConnectionString %>"
SelectCommand="SELECT s.[ShowTimeId], s.[TheatreId], s.[MovieId], s.[FromDate], s.[ToDate], s.[Created],
s.[Modified] FROM [tbl_SShow] s ORDER BY s.[ShowTimeId]">
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
Please give me a solutions
Thanks.

how to keep the textbox values in asp.net gridview after checking the required field validation

I have a regular gridview with insert,edit,update, delete operations as in below image:
Before inserting data to the DB, I am doing the validation on the textboxes if they are filled or empty like this:
if (txtNewID.Text == "")
{
string message = "Please enter ID";
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Alert", "alert('" + message + "')", true);
isValid = false;
}
But after clicking the OK button of the alert message, the values that i added in the required textboxes are getting lost. How to keep the values of the textboxes in gridview?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Code, Type" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand" ShowFooter="True" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<tr>
<td class="style1" >
<asp:GridView ID="gridID" DataKeyNames="Tracker_ID , Current_Status" runat="server"
GridLines="Both" Width="600px" BorderColor="Black"
ShowFooter="true" AutoGenerateColumns="false"
onrowcancelingedit="gridID_RowCancelingEdit"
onrowediting="gridID_RowEditing" onrowcommand="gridID_RowCommand"
onrowdeleting="gridID_RowDeleting" onrowdatabound="gridID_RowDataBound" onrowupdating="gridID_RowUpdating"
>
<Columns>
<asp:TemplateField HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10" HeaderText="ID#">
<EditItemTemplate>
<asp:TextBox ID="ID" BorderWidth="1" Text='<%# Eval("ID") %>' Width="50px" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewID" BorderWidth="1" Width="50px" runat="server"></asp:TextBox> </FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblID" Font-Size="Smaller" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID Description" HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10">
<EditItemTemplate>
<asp:TextBox ID="IDDesc" Text='<%# Eval("ID_Description") %>' Width="99px" BorderWidth="1" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewIDDesc" BorderWidth="1" Width="99px" runat="server"></asp:TextBox> </FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblIDDesc" Font-Size="Smaller" Text='<%# Bind("ID_Description") %>' runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="HCL Author" HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10">
<EditItemTemplate>
<asp:TextBox ID="txtHclAuthor" Text='<%# Eval("HCL_Author") %>' Width="95px" BorderWidth="1" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewHclAuthor" BorderWidth="1" Width="95px" runat="server"></asp:TextBox> </FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblHclAuthor" Font-Size="Smaller" Text='<%# Bind("HCL_Author") %>' runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Xerox Author" HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10">
<EditItemTemplate>
<asp:TextBox ID="txtXeroxAuthor" Text='<%# Eval("Xerox_Author") %>' Width="95px" BorderWidth="1" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewXeroxAuthor" BorderWidth="1" Width="95px" runat="server"></asp:TextBox> </FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblXeroxAuthor" Font-Size="Smaller" Text='<%# Bind("Xerox_Author") %>' runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Track" HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10">
<EditItemTemplate>
<asp:TextBox ID="IDTrack" Text='<%# Eval("Track") %>' Width="80px" BorderWidth="1" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewIDTrack" BorderWidth="1" Width="80px" runat="server"></asp:TextBox> </FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblIDTrack" Font-Size="Smaller" Text='<%# Bind("Track") %>' runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td> </tr> </ContentTemplate>
</asp:UpdatePanel>
Whenever PostBack event is called then we can loss the page data.Did you place the grid in updatepanel otherwise place it in grid if you didn't get maintain the values in viewstate.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.requiredfieldvalidator.aspx
Bind the validator to the textbox you need to be required before a submit/post is valid using the ControlToValidate property.
Try to find required field validator dynamically on RowDataBoundEvent of Grid View.
TextBox tb=e.Row.FindControl("txtBox") as TextBox;
tb.ValidationGroup=e.RowIndex;
RequiredFieldvalidation rv=e.Row.FindControl("rv") as
RequiredFieldValidator; rv.ControlTovalidate=tb; rv.ErrorMessage;
rv.ErrorMessage="*";
rv.ValidationGroup=e.RowIndex;

Categories