using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.Practices.EnterpriseLibrary.Data; using Microsoft.Practices.EnterpriseLibrary.Common; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } /*Self Note: If * Look at the "Display" property of the (validator in this case) controls in the template column, * when looking at them in "EditTemplate" mode. * * ****Set the "Display" property to "Dynamic" for the Validator controls * * These controls take up space and hence can misalign elements on the gridview when in edit mode, * if you do not do this. * * */ /*protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { lblUID.Text = GridView1.SelectedValue.ToString(); } protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e) { lblError.Text = "RowUpdated"; } */ protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { int x = 0; //GridViewUpdatedEventArgs blah = new GridViewUpdatedEventArgs(); //blah = e; Response.Write("Updating"); GridViewRow row = GridView1.Rows[e.RowIndex]; DateTime date; if (row != null) { Calendar c = row.FindControl("Calendar2") as Calendar; TextBox t = row.FindControl("Textbox1") as TextBox; //Label lblCurrent = row.FindControl("lblBday") as Label; //lblCurrent.Text = c.SelectedDate.ToShortDateString(); //t.Text = c.SelectedDate.ToShortDateString(); //lblError.Text = t.Text; //txtBirthday.Text = t.Text; //lblError.Visible = false; //date = System.Convert.ToDateTime(lblCurrent.Text); //Response.Write(t.Text); //row.FindControl("lblBDay") as Label; //date = System.Convert.ToDateTime(t.Text); //t.Text = date.ToShortDateString(); /*if (c != null) { Response.Write(t.Text); } */ } //if (e.Exception != null) //{ //lblError.Text = "Woops"; //e.ExceptionHandled = true; //e.KeepInEditMode = true; //} // try //{ // x = 3; //lblUID.Text=GridView1.SelectedValue.ToString(); //lblError.Text = "NOOOO"; //x = 5; //x = 10; //txtBirthday.Text = lblError.Text; //SqlDataSource1.Update(); //} //catch (Exception exception) //{ /* if ( != null) { // //GridViewUpdatedEventArgs b = new GridViewUpdatedEventArgs(); lblError.Text = "Woops"; //exception.ExceptionHandled = true; } //handle exception here dude! */ //} } //When the user hits the "Submit" button then we want to //A)Read the input information specified, //B)insert it into the database. //C)Update the gridview to reflect the change to the database. //Go to: //http://codeplex.com/entlib //Click on the "Releases" tab //Download the "Documentation in CHM format" file. //Launch the file you just downloaded (it should be "EnterpriseLibrary.chm" //Click on the "Search" tab and enter in quotes //"configure a connection string" //then read the pane on the right as to how to configure a connection string. protected void btnSubmit_Click(object sender, EventArgs e) { //txtBirthday.Text = "Louis"; lblError.Text = ""; try { //create a db instance Database db = DatabaseFactory.CreateDatabase(); //NOTE: The actual db being worked on is specified in Web.config //This setting can be set using the Enterprise Library Configuration tool. //Simply go to File->Open Application // then navigate to the location where you saved your VS project. //then click on the Web.config file in that directory. //Your project's information should now load in the Enterprise Library Configuration console //Click on "Data Access Application Block." //Under the "General" section, you'll see an entry called "DefaultDatabase". //In this entry you'll see a text field, click on this text field and select the database you wish to use. // //execute the stored procedure "testInsert" which will insert whatever the user //entered into the 3 text boxes (txtFirstName, txtLastname, and txtBirthday) //into the db. db.ExecuteNonQuery("TestInsert", txtFirstName.Text, txtLastName.Text, txtBirthday.Text); //Now we want to bind our db to our gridview so that it shows the updated information. GridView1.DataBind(); //now we set the input boxes to blank after we've read in the user's data txtFirstName.Text=GridView1_CleanInputFields(); txtLastName.Text=GridView1_CleanInputFields(); txtBirthday.Text=GridView1_CleanInputFields(); //SqlDataSource1.Insert(); } catch (Exception exception) { lblError.Text = "Invalid Input - record not inserted"; //do exception handling } } protected string GridView1_CleanInputFields() { return ""; } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { lblError.Text = "Woo"; lblUID.Text = GridView1.SelectedValue.ToString(); } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { //Calendar c; // lblError.Text=e.ToString(); try { //c = (Calendar)r.FindControl("Calendar2"); //lblBirthday.Text = c.SelectedDate.ToShortDateString(); //lblError.Text = "Hi"; //txtBirthday.Text = }catch(Exception exception){ lblError.Text = "Invalid Input my man/woman"; } } //Really sweet reference on exception handling with a gridview's edit - update/cancel 'command' button //http://www.siue.edu/~dbock/cmis460/Module%2014%20--%20GridView%20Control/Module14-GridView.htm#_Update_GridView_Daat protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e) { //System.Collections.ICollection vals; //= e.NewValues.Keys as System.Collections.IDictionary; //vals = e.NewValues.Keys; //vals. //Response.Write(vals.ToString()); //GridViewRow row = GridView1.Rows[e.RowIndex]; //GridView1.Rows[e.RowIn try { if (e.Exception != null) { e.ExceptionHandled = true; e.KeepInEditMode = true; lblError.Text = "Invalid Input my man/woman"; } else { //Label l = row.FindControl("lblBday") as Label; //txtFirstName.Text=l.Text; //Label l = RowC //t.Text = "Boo"; lblError.Text = "Something Wrong"; } //lblError.Text = "Hi"; } catch (Exception exception) { } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { txtBirthday.Text = Calendar1.SelectedDate.ToShortDateString(); Calendar1.Visible = false; //Button1.Text = Calendar1.SelectedDate.ToString(); } protected void Button1_Click(object sender, EventArgs e) { Calendar1.Visible = true; } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow r = e.Row; Label lblCurrent; TextBox txtC; DateTime date; int x=-1; try { lblCurrent = ((Label)r.FindControl("lblBday")); //lblError.Text = if (r.RowType == DataControlRowType.DataRow) { //txtC = (TextBox)r.FindControl("Textbox1"); //if (txtC.Text != null) //{ // lblCurrent.Text = txtC.Text; //} date = System.Convert.ToDateTime(lblCurrent.Text); lblCurrent.Text = date.ToShortDateString(); //r.Cells[1].FindControl } } catch { //send an e-mail programmatically //good in this case if something breaks on your form, //and you want to let the dev know about it. //System.Web.Mail } } //every time that a user chooses a different date on the calendar, //we want: // 1. To not show the calendar anymore // 2. the lblBirthday to reflect the changes. protected void Calendar2_SelectionChanged(object sender, EventArgs e) { GridViewRow r = GridView1.Rows[GridView1.EditIndex]; //(GridViewRow)GridView1.SelectedValue; //Response.Write(r.ToString()); //GridViewRow row = GridView1. //t = (TextBox)r.FindControl("Textbox1"); //Probably will end up using this: TextBox t; //= new TextBox(); t = r.FindControl("TextBox1") as TextBox; Calendar c = (Calendar)sender; t.Text=c.SelectedDate.ToShortDateString(); c.Visible = false; //Response.Write(t.Text); //*/ //GridViewRow r //if (r.RowType == DataControlRowType.DataRow) //{ //c=(Calendar)r.FindControl("Calendar2"); //lblBirthday.Text=c.SelectedDate.ToShortDateString(); //c.Visible = false; //} //lblBirthday.Text = Calendar2.SelectedDate.ToShortDateString(); //Calendar2.Visible = false; } protected void Button2_Click(object sender, EventArgs e) { GridViewRow r = GridView1.Rows[GridView1.EditIndex]; Calendar c = (Calendar)r.FindControl("Calendar2"); c.Visible = true; } protected void TextBox1_TextChanged(object sender, EventArgs e) { } [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { //look at RowUpdating - which is supposedly called before RowDeleting //http://www.gamedev.net/community/forums/topic.asp?topic_id=347236&whichpage=1� //btnNull.Click = true; e.Cancel = true; ModalPopupExtender1.Show(); //e.Cancel = true; //Response.Write("DUDE!!!!!"); //cancel the delete temporarily //pnlDelete.Visible=true; //lblConfirm.Visible=true; //GridViewRow r = GridView1.Rows[e.RowIndex]; //GridViewRow r = GridView1.SelectedRow; //if r.RowState != DataControlRowState.Selected //ModalPopupExtender1.RenderControl(); //ModalPopupExtender1.Show(); //e.Cancel = true; /* Panel p; p = r.FindControl("pnlDelete") as Panel; //pnlDelete.visble = true; p.Visible = true; //AjaxControlToolkit.ModalPopupExtender e; //e = r.FindControl("ModulPopupExtender1") as AjaxControlToolkit.ModalPopupExtender; */ } /*protected void btnDel_Click(object sender, EventArgs e) { //Database db = DatabaseFactory.CreateDatabase(); //IDataReader reader = db.ExecuteReader("TestSelect", Request.QueryString["id"]); try { Button btnDelete = sender as Button; GridViewRow row = (GridViewRow)btnDelete.Parent; txtBirthday.Text="hello"; GridView1.DeleteRow(row.RowIndex); //Request.QueryString[0]; //find the item and remove it //GridView1.Rows[row.RowIndex]; //GridView1.DeleteRow(row.RowIndex); //GridView1.DataBind(); } catch (Exception exception) { txtBirthday.Text = "NOOOOOOOO-dude"; } //db.ExecuteNonQuery("TestDelete", ); /* GridViewRow r = GridView1.Rows[GridView1.SelectedIndex]; Panel p; p = r.FindControl("pnlDelete") as Panel; p.Visible = true; /* AjaxControlToolkit.ModalPopupExtender e; e = r.FindControl("ModulPopupExtender1") as AjaxControlToolkit.ModalPopupExtender; */ /* } */ protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if ( e.CommandName.Equals("Delete")) { //ModalPopupExtender1.Show(); //Response.Write("Hello"); } } protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e) { } protected void btnYes_Click1(object sender, EventArgs e) { } }