why can't Gridview update if empty data is presented into the textfield of Gridview edit

 HI all,

I have basically two fields which are Name,description. Whenever I was trying to edit fields(name, description) the command event is not firing because description(textbox) is empty. Why and how to fix this issuse. Because Name field is a required one and description is optional it could be empty one. Any help please


thanks and regards,



4/24/2009 1:19:08 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 35

Can you please give your code. This can help us understand and solve your problem!!

4/24/2009 1:36:36 PM

Here is the code  

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id"
DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None">
<RowStyle BackColor="#EFF3FB" />
<asp:TemplateField HeaderText="Name" SortExpression="Name" HeaderStyle-HorizontalAlign="Left">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
<asp:TemplateField HeaderText="Description" SortExpression="Description" HeaderStyle-HorizontalAlign="Left" >
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
<asp:TemplateField HeaderText="CreatedDate" SortExpression="CreatedDate" HeaderStyle-HorizontalAlign="Left">
<asp:Label ID="Label3" runat="server" Text='<%# Bind("CreatedDate") %>'></asp:Label>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
No Non - Profit Organizations Created
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
DeleteCommand="DELETE FROM [NonProfitOrganizations] WHERE [Id] = @Id"
InsertCommand="INSERT INTO [NonProfitOrganizations] ([Name], [Description], [CreatedDate]) VALUES (@Name, @Description, @CreatedDate)"
SelectCommand="SELECT [Name], [Id], [Description], [CreatedDate] FROM [NonProfitOrganizations] ORDER BY [CreatedDate] DESC"
UpdateCommand="UPDATE [NonProfitOrganizations] SET [Name] = @Name, [Description] = @Description, [CreatedDate] = @CreatedDate WHERE [Id] = @Id">
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="CreatedDate" Type="DateTime" />
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="CreatedDate" Type="DateTime" />
4/24/2009 1:50:08 PM

Hi vijaycanaan ,

From your code, I can not find out any evidence given to substantiate the claim that description(textbox) is empty contribute to command event can't be fired.

I see the requiredfieldvalidator is used to validate Name field instead of description field. I don't think that will prohibit fire command event if des field is empty.


Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
4/29/2009 5:19:44 AM

Similar Artilces:

What's wrong with DataBind() in GridView control? The data in GridView can't be updated when the datasource have changed!
What's wrong with DataBind() in GridView control? The data in GridView can't be updated when the datasource have changed! I bind the different datasource to the Gridview when I change the node of TreeView, the GridView control always display the same data when I click different the node of TreeView control,why?but I can get the different data in GridView when I click the Button1 or Button2. //-------------------Program Code (You may save it as a ASPX file and run it)--------------------------------<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http:/...

I can't update data when using GridView control.
Hi all.I enable editing option in  GridView control but it doesn't work.When updating I can't see anything happens.What's wrong ?Thanks Did you use two-way binding?  Make sure you use <%#Bind("xxx")%> instead of  <%#Eval("xxx")%>. Now, I can update the data as expecting.But I still have one problem.When using ntext type and updating, an unhandled exception occurred: The data types ntext and nvarchar are incompatible in the equal to operator.But when I change ntext type to nvarchar(max) everything goes fine.How can I solve this problem without changing ntext to ...

Easy question, but I can't figure it out. Gridview nested in datalist .. I need to access the Gridview caption, but can't
To be more clear ...The datalist contains ItemIds, the gridview contains applications ids. When the page loads I need to check the database to see if the itemid / application id link already exists and if so check the checkbox. Everyhting works, except I can't get the itemid to check the DB with. Any suggestions, what am I doing wrong? I'm getting the object reference not set to the instance of an object error. TIA,Kyle 1 <asp:DataList ID="ItemsDataList" runat="server" DataSourceID="ObjectDataSource1"> 2 <ItemTemplate> 3 <h2>Part...

Why can't I Enable Editing on a Gridview that gets it's data from a View through an SqlDataSource?
Hi, I think the title explains it all really. I cannot configure the SqlDataSource to add Insert, Update and Delete statements - not through the wizard anyway. The view combines two tables, each containing 3 columns. I have tried using different combinations of columns, and ended up selecting all of them (making sure the foreign key column of the first table was given a different alias to the primary key column of the second table) but I still cannot enable editing. Cheers, PatrickDisco Patrick writes web applications using:Visual Studio 2008ASP.NET 3.5C#SQL Server 2008 Use stored pr...

I'm trying to update a GridView by using an Update Panel. Can't get the update to work.
Even when the GridView first loads, none of the new rows that I have added to the database will show up. Any help is appreciated. Thanks.  Code:<asp:ScriptManager ID="ScriptManager1" runat="server" />        <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">        <Triggers>            <asp:AsyncPostBackTrigger controlid="btnRefresh" eventname="Click"...

Can't update data from gridview when datakey column is hidden
I have the code below, which works fine, but, I want to hide the ID column. When I set the visible to false, for that column, I can no longer update the radio buttons, since, I think, the value of the ID is not there. thanks for looking     <asp:GridView ID="GridViewContactOptionsX" runat="server"         AutoGenerateColumns="False" DataKeyNames="ID"         DataSourceID="AccessDataSourceContactOptionsX" Width="100%"     &nb...

Can't reach dynamically added control on update in GridView
Hi-I have a GridView control that has a dynamically added control in one column. What sort of control gets added is based on what the content is - could be a textbox, RTF Editor (instead of a normal textarea, similar to what I'm writing this post in), datepicker, etc. I'm getting the data into the control just fine when I go into edit mode for a row, but can't seem to get the contents of that control when I try to save changes and update that row.I've tried using the RowUpdating event for the GridView control as well as the Updating event for the SQLDatasource control that the GridView is bo...

 I wan’t to use input validation in my GridView and that’s why I want one of my fields to be an TemplateField. Everything looks OK, BUT I can’t update any data.   What am I missing again?   <asp:GridView ID="gvResultat_IPO_A" runat="server" AutoGenerateColumns="False" DataSourceID="odsResultat_IPO_A" EnableViewState="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

First gridview's selected row doesn't update second gridview's objectdatasource
 HelloI got 2 gridviews on a page, each with its own ObjectDataSource. The first gridview fills itself just normally, no problem there. The second gridview needs to fill itself with other data, where the primary key is the primary key of the selected row of the first gridview.schematically:gridview1 row: IDfield, x, y, zrow: IDfield, x, y, z (-> this row is selected)row: IDfield, x, y, z gridview2 row:IDfield_of_selected_row_in_gridview1, a, b, c I tried to do this by configuring the ObjectDataSource behind gridview2 with a parameter pointing to gridview1.selectedValue. (by usin...

Help! problem! Can't delete or edit in GridView of VWD Beta 2.0 if the SelectCommand of the GridView put in code page!
I find a problem:When I put SelectCommand of a SqlDataSource in code page(for example: SqlDataSource1.SelectCommand = "SELECT [ID], [PName] FROM [Person]";) and clear SelectCommand'content in Html page, the delete and edit of the GridView (for example:GridView1) don't work!Please help me! To get those, you need to add UpdateCommand and DeleteCommand also in your SQLdataSource!http://beta.asp.net/QuickStartv20/aspnet/doc/data/databases.aspx#gridview will have some example on how to enable Edit/Delte! Please have a glance of that link, it might helps you!Sreedharhttp://www.w3...

Can't get GridView: Edit/Update Mode to work on a Many-to-Many table...
Hello everyone... I'm trying to use the .NET 2.0 GridView and SqlDataSource controls to perform an edit/update on a simple user list. I'm trying to do it without writing code - as I think it should be possible. The procedure is pretty basic. But I'm getting hung up somewhere - I hope you guys can help me. Here's how I envision the basic workflow: 1) User selects a REGION from dropdown list - which fills an AREA dropdown list with AreaIDs associated with the RegionID. 2) User selects an AREA from dropdown list and clicks a button to build a list of AreaIDs and ContactIDs associat...

Please help! The GridView 'GridView1' fired event RowEditing which wasn't handled ?????? Or GridView shows data automatically !!!!!!!!
i have created a webpage with these controls:- 1 textbox : used to input a string to search information from database - 2 buttons : one is SEARCH and another is CANCEL - 1 GridView : used to present the result of searching. It also contains Edit collumn - 1 SqlDataSource named SqlDataSource1 with SELECT satement and UPDATE satement running well (I tested them already!) The problem is that : - case 1: i set SqlDataSource as DataSource of GridView and do not use C# code. When i enter data to TextBox and click any of 2 buttons, the search result is showed...

VB.NET: How can I create a new record in an empty gridview? GV doesn't even show!
 Hi, I have  a GV that is linked to a DetailsView, DV offers possibility to add new records. Now, after clearing the database from all test-records, I found that obviously the empty GV doesn't have records and so I cannot get into the details view and launch the New-func :(   What is the best way to deal with that? ThanksMichael First off, does your New Button have to be within the GridView? If not add your Button outside of the GridView. Else, consider placing your New Button within the EmptyDataTemplate.Thanks, EdMicrosoft MVP - ASP/ASP.NET Well, a button ...

Web resources about - why can't Gridview update if empty data is presented into the textfield of Gridview edit - asp.net.presentation-controls

Resources last updated: 12/16/2015 3:36:56 PM