GridviewHandleError

Vipul
Posted by in ASP.NET category on for Beginner level | Views : 2713 red flag

These code for Textbox of gridview can't be blank while upadating record.
Introduction

These code is helpful While inserting or updating records in gridview you need following exception for avoiding blank records.You can see it in above image.

Write following codes for it

<style type="text/css">

.error

{

display:block;

color:red;

font:bold 16px Arial;

margin:10px;

}

</style>

<asp:Label ID="lblError"

EnableViewState="false"

CssClass="error"

runat="Server" />

<asp:GridView

id="grdMovies"

DataKeyNames="Id"

AutoGenerateEditButton="true"

DataSourceID="srcMovies"

runat="Server" OnRowUpdated="grdMovies_RowUpdated" />

<asp:SqlDataSource ID="srcMovies"

SelectCommand="select id,title from movies"

UpdateCommand="update movies set title=@title where id=@id"

ConnectionString="Your string"

runat="server" ProviderName="System.Data.SqlClient" />

 

protected void grdMovies_RowUpdated(object sender, GridViewUpdatedEventArgs e)

{

if (e.Exception != null)

{

lblError.Text = "Can't be blank";

e.ExceptionHandled = true;

}

}

Page copy protected against web site content infringement by Copyscape

About the Author

Vipul
Full Name: vipul vk
Member Level: Starter
Member Status: Member
Member Since: 4/15/2009 9:08:15 PM
Country:

http://www.dotnetfunda.com
Working as a software developer

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)