textchanged Event is working.. but...updatenutton has to pressed two times..

Posted by Vinu under ASP.NET on 3/1/2013 | Points: 10 | Views : 1203 | Status : [Member] | Replies : 0
protected void txtRoomname1_TextChanged(object sender, EventArgs e)
{
//Gridview Textbox change events Check Room Name Availability.

GridViewRow row = ((GridViewRow)((TextBox)sender).NamingContainer);
string id = GdVwRoom.DataKeys[row.RowIndex].Value.ToString();


GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent;
TextBox txtrname = (TextBox)currentRow.FindControl("txtRoomname1"); //Gridview textbox Room Name
Label lblgridmsg = (Label)currentRow.FindControl("lblexist");

string selRname = "select * from Room where RoomName='" + txtrname.Text + "'"; //Select Room Name for checking duplicate RoomName

OleDbDataAdapter daRName = new OleDbDataAdapter(selRname, con);
DataTable dtRname = new DataTable();
daRName.Fill(dtRname);

int cntRname = dtRname.Rows.Count; //Count Room Name

if (cntRname > 0)
{
lblgridmsg.Text = "Room Name Already Exist....!!!";
pnlgridview.Visible = true;
pnladd.Visible = false;
}
else if (txtrname.Text == "")
{
lblgridmsg.Text = "This Field Can't be Empty..!! ";
}
else
{
lblgridmsg.Text = "";
goto up;
}

OleDbCommand cmd = new OleDbCommand("Select * from Room where RoomId = '" + id + "'", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

if ((dt.Rows[0]["RoomName"].ToString() == txtrname.Text))
{
lblgridmsg.Text = "";
pnlgridview.Visible = true;
pnladd.Visible = false;

}
else
{

}

}

protected void GdVwRoom_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
GridViewRow row = (GridViewRow)GdVwRoom.Rows[e.RowIndex];
string id = (GdVwRoom.DataKeys[e.RowIndex].Value.ToString()); //Find Datakey Value
TextBox rname = (TextBox)row.FindControl("txtRoomname1"); //find textbox of gridview for update
Label lblgridmsg = (Label)row.FindControl("lblexist");

continue;

up:if(lblgridmsg.Text == "")
{
OleDbCommand cmdupdate = new OleDbCommand("update Room set RoomName = '" + rname.Text + "' where RoomId = '" + id + "'", con);
con.Open();
cmdupdate.ExecuteNonQuery();
con.Close();
LblMsg.Text = "";
LblErr.Text = "";
Lblup.Text = "";
GdVwRoom.EditIndex = -1;
bind();
lblupdate.Text = "Room Name Updated Successfully...!! ";
pnlgridview.Visible = true;
pnladd.Visible = false;

}

else
{
lblgridmsg.Text = "This is not Allowed...!!";

}
}

catch (Exception ex)
{
Lblup.Text = ex.Message;
}
}

Vinu malli


Responses

(No response found.)

Login to post response