Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai
I am filling grid from table . In that table i have decimal,int & string datatypes values. here i am get the all values to assign grid , while assigning except decimal datatype columns remaining columns i put it in readonly=true mode.
so, in gridview i am click on EDIT button those decimal datatype values are in textboxes. When changing the text in textbox i want to find the text formate for that i am not finding the textbox. so, please help me how to find the textbox.



XML
<asp:GridView ID="gvProcessSalary" runat="server" CellPadding="4" ForeColor="#333333" AllowPaging="true" PageSize="10"
                                               AutoGenerateEditButton="true" AutoGenerateColumns="false"   OnRowEditing="gvProcessSalary_OnRowEditig" OnPageIndexChanging="gvProcessSalary_OnPageIndexChanging"
                                               SkinID="Professional" OnRowUpdating="gvProcessSalary_OnRowUpdating"  OnRowCancelingEdit="gvProcessSalary_OnRowCancellingEdit"   >
                                           </asp:GridView>
Posted
Comments
JoCodes 28-Nov-13 1:08am    
Can you post the complete gridview markup code which includes your columns?
MANI 14 28-Nov-13 1:17am    
DataTable dtSalProcess = ssBO.GetSalaryProcess(ssEntity);
public void BintoGrid()
{
foreach (DataColumn col in dtSalProcess.Columns)
{
BoundField bfield = new BoundField();

//Initalize the DataField value.
bfield.DataField = col.ColumnName;

//Initialize the HeaderText field value.
bfield.HeaderText = col.ColumnName;
if (col.ColumnName == "UHID" || col.ColumnName == "EmpID" || col.ColumnName == "Cal_Month" || col.ColumnName == "Cal_Year" || col.ColumnName == "Freezed")
bfield.Visible = false;

if (col.ColumnName == "EmpName" || col.ColumnName == "StaffNo" || col.ColumnName == "Month" || col.ColumnName == "NoOfDays" || col.ColumnName == "Cal_Year" || col.ColumnName == "Total_Earning" || col.ColumnName == "Total_Deduction" || col.ColumnName == "Net_Salary")
{
bfield.ReadOnly = true;
bfield.ItemStyle.BackColor = System.Drawing.Color.AliceBlue;//LightBlue;//.LightSteelBlue;
}
gvProcessSalary.Columns.Add(bfield);
}

Session["dtSalProcess"] = dtSalProcess;
protected void gvProcessSalary_OnRowEditig(object sender, GridViewEditEventArgs e)
{
gvProcessSalary.EditIndex = e.NewEditIndex;

BindProcessSalDetails();

}
}
protected void gvProcessSalary_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
for (int i = 0; i < dt.Columns.Count; i++)
{

if (dt.Columns[i].ColumnName != "UHID" && dt.Columns[i].ColumnName != "EmpID" && dt.Columns[i].ColumnName != "Cal_Month" && dt.Columns[i].ColumnName != "Total_Earning" && dt.Columns[i].ColumnName != "Total_Deduction" && dt.Columns[i].ColumnName != "Net_Salary")
{
if (dt.Columns[i].DataType.Name == "Decimal")
{

string str = (gvrow.Cells[i + 1].Controls[0] as TextBox).Text.ToString();
(gvrow.Cells[i + 1].Controls[0] as TextBox).AutoPostBack = true;
if (str == "" || str == ".")
str = "0.00";
else if ((!str.Contains(".")))
str = str + ".00";

Regex regex = new Regex(@"^[0-9]+\.?[0-9]{1,2}$");

if (regex.IsMatch(str))
{
txtFlag = 1;
if (str == "0.00")
dt.Rows[j][i] = Convert.ToDecimal(str.ToString());
else
dt.Rows[j][i] = Convert.ToDecimal((gvrow.Cells[i + 1].Controls[0] as TextBox).Text.ToString());
}
}
Where is the problem exactly? On which line?
MANI 14 28-Nov-13 1:40am    
In gridview rows clicking edit button. Then decimal datatype columns are comes as textboxes. while entering text in textbox i want to find the text whether text is correct or not at leaving that text box when focus is leave that textbox.
Add one Text Changed Event either on Server or Client side. Then check if the data is decimal or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900