Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridview item template with 4 columns as
C#
Row No.   Start Date    Login time     Logout
1         10/25/2013    9.30           6.30
2         10/26/2013    12.30          9.30
3         10/27/2013    12.30          9.30

AddNewRow       SubmitButton        ClearButton


here for Start Date i used calender extender. and user can add new row to gridview
the user enteres all the data with different date and finally clicks on submits button.

But my intension is:
while entering Start date in the textbox, if user selects same date for any textbox,
it should show alert message as duplicate.

my code is:
C#
int rowIndex = 0;
        if (ViewState["CurrentTable"] != null)
        {
            DataTable gvdata = (DataTable)ViewState["CurrentTable"];
            DataRow drCurrentRow = null;
            if (gvdata.Rows.Count > 0)
            {
                for (int i = 1; i <= gvdata.Rows.Count; i++)
                {
                    //extract the TextBox values
TextBox textstartdt = (TextBox)GridView1.Rows[rowIndex].FindControl("txtfromdt");
drCurrentRow = gvdata.NewRow();
drCurrentRow["RowNumber"] = i + 1;
gvdata.Rows[i - 1]["Start Date"] = textstartdt.Text;
gvdata.Rows[i - 1]["in"] = dropdownlist1.Text;
gvdata.Rows[i - 1]["out"] = dropdownlist2.Text;
rowIndex++;
                }
for (int i = 0; i <= gvdata.Rows.Count; i++)
            {
                TextBox textstartdt = (TextBox)GridView1.Rows[i].FindControl("txtfromdt");
                if (textstartdt.Text != "" || textstartdt.Text != null)
                {                    
if (textstartdt.Text == gvdata.Rows[i]["Start Date"].ToString())
                    {
                        System.Windows.Forms.MessageBox.Show("Your selected startdate is duplicated, please change date..!");
                    }
                }
            }

But i am getting this alert for duplicate and different dates.
Posted
Updated 20-Oct-13 22:38pm
v3
Comments
Thanks7872 21-Oct-13 4:43am    
If you want to check the two textbox for same values,then you have to do it client side with JavaScript because before postback,server would not be aware about what happened at client.
CodeBlack 21-Oct-13 8:47am    
what values you are getting for
textstartdt.Text and
gvdata.Rows[i]["Start Date"].ToString()
?

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