The previous article is to use the GridView control to achieve the display and deletion of data, this section of the design page, using the GridView control to implement the data update operation, when the news content is not entered when the update prompts "cannot be empty."
Learning content:
Learning Tasks one uses the GridView control to implement updates to information
Step one: The data source control defines the data by writing the code in the Newschuli.cs page as follows:
public static void Modifynews (Newsclass news1)
{
using (SqlConnection cn = dbconn. Getconnection ())
{
CN. Open ();
SqlCommand cm = new SqlCommand ();
Cm. Connection = cn;
String sql = "Update news set title = @content, contents= @as where id= @id";
Cm.commandtext = SQL;
Cm. Parameters.addwithvalue ("@content", news1. Title);
Cm. Parameters.addwithvalue ("@as", news1. Contents);
Cm. Parameters.addwithvalue ("@id", news1.id);
Cm. ExecuteNonQuery ();
}
Step two: The ObjectDataSource control gets the data from the data source, selects the Update tab, sets the Select method to Modifynews (Newsclass news1), and clicks Next.
Step three: Set the DataKeyNames property to the ID.
Step four: Add edit columns and delete columns. Open the GridView Task menu, select the Edit Columns command to open the Fields dialog box, expand the + before commandfired in the Available fields list in the upper left, select Edit, Update, cancel, and delete, and click OK.
Learning Task Two sets the template column.
instance One: input non-null validation
STEP1: Open the Fields dialog box and select the News headlines option. "Convert this segment to templatefired" hyperlink to a template column at the bottom right of the stand-alone machine.
STEP2: Open the GridView Task menu, select Edit Template entry, set a data validation control Requiredfiredvalidator to the EditItemTemplate template entry, and implement Non-null validation.
Example two: Add a dialog box to confirm deletion before deleting
STEP1: Opens the Fields dialog box and selects the delete option. Click the "Convert this segment to templatefired" hyperlink in the lower-right section to convert it to a template column.
STEP2: Add a client event OnClientClick, write JavaScript script: onclientclick= "return confirm (' Confirm to delete ')"
Run Effect chart:
The above is the entire content of this article, I hope you will be proficient in using the GridView control to achieve data modification has helped.