Update is not working on GridView - asp.net

Hey guys,
I have a GridView which is binded to SqlDataSource, everything works fine, just update does not works, i am calling stored procedure, and all parameters and its dataTypes are proper, actually none of the events work on that update button, i tried to change the CommandName to "Change" and created OnCommand Event, and wrote Response Message in the code. but nothing happens on the update button, cancel button works fine, and also delete works, there is just a problem with update, even if the procedure has some issue atleast event should raised, i even checked in Sql Profiler, but the update procedure never hits Sql Server 2008...
But when i remove SqlDataSource then everything works fine also the update command with same stored procedure.
Please help me out for this, i have stuck here badly
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="Title" EnableModelValidation="True"
ForeColor="#333333" GridLines="None"
ShowFooter="True" Width="950" AllowPaging="true" PageSize="10">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<%# Eval("Title") %>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="txtEditTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quote">
<ItemTemplate>
<%# Eval("Quote") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditQuote" runat="server" Text='<%# Bind("Quote") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField >
<asp:TemplateField HeaderText="Quote Link">
<ItemTemplate>
<%# Eval("QuoteLink") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditQuoteLink" runat="server" Text='<%# Bind("QuoteLink") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Published">
<ItemTemplate>
<asp:CheckBox ID="chkBox" runat="server" Checked='<%# Convert.ToBoolean(Eval("Published")) %>' Enabled = "false" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="chkEditBox" runat="server" Checked='<%# Bind("Published") %>' Enabled="true" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PublishedDate">
<ItemTemplate>
<%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem,"PublishedDate")).ToString("MM.dd.yyyy") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditPublishedDate" runat="server" Text='<%# Bind("PublishedDate") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Commands">
<ItemTemplate>
<asp:ImageButton runat="server" ID="Edit" ImageUrl="/images/edit.gif" CommandName="Edit" />
<asp:ImageButton runat="server" ID="Delete" ImageUrl="/images/delete.gif" CommandName="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button runat="server" ID="btn1" CommandName="Update" Text="Update" />
<asp:ImageButton runat="server" ID="Cancel" ImageUrl="/images/delete.gif" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" HorizontalAlign="Left" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
DeleteCommand="DELETE FROM [Quotes] WHERE [Title] = #Title"
SelectCommand= "SELECT [Title], [Quote], [QuoteLink], [Published], [PublishedDate] FROM [Quotes]"
UpdateCommand="sp_UpdateQuotes" UpdateCommandType="StoredProcedure"
InsertCommand="INSERT INTO [Quotes] ([Title], [Quote], [QuoteLink], [Published], [PublishedDate]) VALUES (#Title, #Quote, #QuoteLink, #Published, #PublishedDate)">
<DeleteParameters>
<asp:Parameter Name="Title" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Quote" Type="String" />
<asp:Parameter Name="QuoteLink" Type="String" />
<asp:Parameter Name="Published" Type="Boolean" />
<asp:Parameter Name="PublishedDate" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Quote" Type="String" DefaultValue = "QUotes are simple" />
<asp:Parameter Name="QuoteLink" Type="String" DefaultValue = "QUotes are Linked" />
<asp:Parameter Name="Published" Type="Boolean" DefaultValue = "False" />
<asp:Parameter Name="PublishedDate" Type="DateTime" DefaultValue = "05/15/2011" />
</UpdateParameters>
</asp:SqlDataSource>
ALTER PROCEDURE [dbo].[sp_UpdateQuotes]
#Title varchar(max),
#Quote varchar(max),
#QuoteLink varchar(max),
#Published bit,
#PublishedDate DateTime
AS
BEGIN
UPDATE dbo.Quotes SET
Quote = #Quote,
QuoteLink = #QuoteLink,
Published = #Published,
PublishedDate = #PublishedDate
WHERE Title = #Title
If #Published = 1
BEGIN
UPDATE dbo.Quotes SET Published = 0 WHERE Title <> #Title AND Published = 1
END
END
Hope this would give you clear idea about what is messing me for update

You have not passed the #Title parameter, which is your primary Key in your stored procedure and is used in the where Clause.
If you want to see that there is no Title Parameter in Update Parameters:
<UpdateParameters>
<asp:Parameter Name="Quote" Type="String" />
<asp:Parameter Name="QuoteLink" Type="String" />
<asp:Parameter Name="Published" Type="Boolean" />
<asp:Parameter Name="PublishedDate" Type="DateTime" />
</UpdateParameters>
If you add the Title Parameter, it will work:
<asp:Parameter Name="Title" Type="String" />

I also had a problem with a GridView that was not updating. Inspection of the e.Newvalues Dictionary in the GridView's RowUpdating event showed that the old values for the record were being sent to the database UPDATE query. DataKeyNames was not my problem; I had it set correctly. The WHERE clause of my SELECT query referenced a control parameter against a TextBox on my form. I had inadvertently set EnableViewState for this textbox to "False". Because of this, the GridView was rebinding itself before the UPDATE occurred. Setting EnableViewState on the TextBox to "True" fixed the problem.
Protected Sub MyGridView_RowUpdating _
(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) _
Handles MyGridView.RowUpdating
' Inspect the parameters being sent to the database for an ASP NET GridView UPDATE.
Dim I As Integer
I = 0
For Each MVO As System.Collections.DictionaryEntry In e.OldValues
If MVO.Value Is DBNull.Value OrElse MVO.Value Is Nothing Then
Debug.Print(I.ToString + ": " + MVO.Key + " Value: ")
Else
Debug.Print(I.ToString + ": " + MVO.Key + " Value: " + MVO.Value.ToString)
End If
I += 1
Next MVO
I = 0
For Each MVN As System.Collections.DictionaryEntry In e.NewValues
If MVN.Value Is DBNull.Value OrElse MVN.Value Is Nothing Then
Debug.Print(I.ToString + ": " + MVN.Key + " Value: ")
Else
Debug.Print(I.ToString + ": " + MVN.Key + " Value: " + MVN.Value.ToString)
End If
I += 1
Next MVN
End Sub

Related

Updating value picked from DDL in DetailView

(I found the way it's supposed to be done as shown in my Answer below.
I'm editing my question and deleting the code I initially put here, which was a mess, leaving just the definitions).
Win7, ASP4.5, empty_web_app in VS2013 with C#. Recreated in a very simple project accessing two tables:
1st table "Students"
student_ID
student_name
student_course_ID (is Forign Key)
2nd table "Courses"
course_ID
course_name
In my web page I have DetailView1 showing details of student who's student_ID is taken from txbStudent_ID.
DetailView1 has Edit Delete and New.
When in UPDATE or INSERT mode I need to show the course_name (rather then the course ID) in a drop-down-list and update/insert accordingly.
No code behind.
My answer below is applicable to GRIDVIEW as well.
Gadi
I was so wrong they way I coded my aspx.
So here is the right way to do it, for future beginners like I am now...
(with the help of https://msdn.microsoft.com/en-us/library/ms178294(v=vs.140).aspx)
<asp:Label ID="Label1" runat="server" Text="Student_ID"></asp:Label>
<asp:TextBox ID="txbStudent_ID" runat="server"></asp:TextBox>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="student_ID" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="student_ID" HeaderText="student_ID" InsertVisible="False" ReadOnly="True" SortExpression="student_ID" />
<asp:BoundField DataField="student_name" HeaderText="student_name" SortExpression="student_name" />
<asp:TemplateField HeaderText="student_course_ID" SortExpression="student_course_ID">
<EditItemTemplate>
<asp:DropDownList
ID="DropDownList1"
runat="server"
DataSourceID="SqlDataSource2"
DataTextField="course_name"
DataValueField="course_ID"
SelectedValue='<%# Bind("student_course_ID") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList
ID="DropDownList2"
runat="server"
DataSourceID="SqlDataSource2"
DataTextField="course_name"
DataValueField="course_ID"
SelectedValue='<%# Bind("student_course_ID") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label
ID="Label1"
runat="server"
Text='<%# Bind("student_course_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowInsertButton="True" ShowDeleteButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:Course_Student_Connection %>"
InsertCommand="INSERT INTO [Students] ([student_name], [student_course_ID]) VALUES (#student_name, #student_course_ID)"
SelectCommand="SELECT * FROM [Students] WHERE ([student_ID] = #student_ID)"
UpdateCommand="UPDATE [Students] SET [student_name] = #student_name, [student_course_ID] = #student_course_ID WHERE [student_ID] = #student_ID"
DeleteCommand="DELETE FROM [Students] WHERE [student_ID] = #student_ID">
<DeleteParameters>
<asp:Parameter Name="student_ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="student_name" Type="String" />
<asp:Parameter Name="student_course_ID" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txbStudent_ID" Name="student_ID" PropertyName="Text" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="student_name" Type="String" />
<asp:Parameter Name="student_course_ID" Type="Int32" />
<asp:Parameter Name="student_ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"
ConnectionString="<%$ ConnectionStrings:Course_Student_Connection %>"
SelectCommand="SELECT [course_ID], [course_name] FROM [Courses]">
</asp:SqlDataSource>
I do hope it will save some time for others.
Stackoverflow is THE greatest and by far the best Q&A site on the web!!!
Gadi.

Input string was not in a correct format vb.net/asp.net

Here's my formview..
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="recid">
<EditItemTemplate>
RECID:
<asp:TextBox ID="recid" runat="server" Text='<%# Eval("RECID") %>' ReadOnly="true" />
<br />
SHIPPER:
<asp:TextBox ID="shipper" runat="server" Text='<%# Bind("SHIPPER") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:FormView>
here's my sqldatasource1
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM IMPORT WHERE (RECID = ?)"
UpdateCommand="UPDATE IMPORT SET SHIPPER=#shipper WHERE RECID=#recid" >
<SelectParameters>
<asp:ControlParameter ControlID="Label1" Name="RECID" PropertyName="Text" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="recid" Type="Int32" />
<asp:Parameter Name="shipper" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Now, my problem is that everytime I update the page, this is the error Input string was not in a correct format.
I tried changing the #recid in the UpdateCommand into a constant UpdateCommand="UPDATE IMPORT SET SHIPPER=#shipper WHERE RECID=11186" this worked well, the update was successful.
I think the #recid is being treated as a string here in the UpdateCommand. Can someone please help me? What do I need to do in order to change the data type of #recid to Integer?
Thanks!
First thing you need to fix is to bind raceid with the textbox like below:
<asp:TextBox ID="recid" runat="server" Text='<%# Bind("RECID") %>' ReadOnly="true" />
Now there's a question about provider. In select command you have used RACEID = ?, ? is used for OleDb or Odbc. If you are using any of them, you have to change Update Command to this:
UpdateCommand="UPDATE IMPORT SET SHIPPER=? WHERE RECID=?"
And UpdateParameters to this (Notice their order):
<UpdateParameters>
<asp:Parameter Name="shipper" Type="String" />
<asp:Parameter Name="recid" Type="Int32" />
</UpdateParameters>
I would recommend reading this MSDN article: Using Parameters with the SqlDataSource Control

InsertCommand into Header Template

Trying to insert three textboxes into the header of a gridview and with a button execute an "INSERT INTO" into the database.
In my online server database: idt is int, datetime is varchar, and col1,col2,col3 are numeric.
<asp:SqlDataSource
id="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:connone %>"
SelectCommand="SELECT * FROM [test];"
InsertCommand="INSERT INTO [test] [datetime],[col1],[col2],[col3] VALUES #datetime,#col1,#col2,#col3;"
runat="server">
<InsertParameters>
<asp:Parameter Name="datetime" Type="String" />
<asp:Parameter Name="col1" Type="Double" />
<asp:Parameter Name="col2" Type="Double" />
<asp:Parameter Name="col3" Type="Double" />
</InsertParameters>
</asp:SqlDataSource>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
SqlDataSource1.InsertParameters("#datetime").DefaultValue = DateTime.Now.ToString()
SqlDataSource1.InsertParameters("#col1").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol1"), TextBox).Text
SqlDataSource1.InsertParameters("#col2").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol2"), TextBox).Text
SqlDataSource1.InsertParameters("#col3").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol3"), TextBox).Text
SqlDataSource1.Insert()
End Sub
<asp:GridView ID="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
AutoGenerateColumns="False"
DataKeyNames="idt">
<Columns>
<asp:BoundField DataField="idt" HeaderText="idt" Readonly="true" SortExpression="idt" />
<asp:BoundField DataField="datetime" HeaderText="datetime" SortExpression="datetime" />
<asp:TemplateField SortExpression="col1">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol1" text="col1" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="col2">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol2" text="col2" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="col3">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol3" text="col3" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
</asp:GridView>
I suggest to remove "#" in InsertParameters as follows:
SqlDataSource1.InsertParameters("col1").DefaultValue =
((TextBox)GridView1.HeaderRow.FindControl("TextBoxHeadercol1")).Text;
this should work.

ASP VB - How to update a database where the selected item is from a dropdown list using a datasource

Hi I am new to ASP and was able to create a dropdown list which list all the items from my table (DB2_INSTANCES).
Now I need to update a second table (PROCESS) with the value selected DB2_DSN. The table does not allow Null values.
If I use "SelectedValue='<%# Bind("DB2_DSN") %>' within my asp:DropDownList after I set the
DataSourceID="SqlDataSource6" DataTextField="INSTANCE" DataValueField="INSTANCE"
I get an error:
"'DropDownList6' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value "
If I change to "SelectedValue='<%# Bind("INSTANCE") %>' within my asp:DropDownList after I set the
DataSourceID="SqlDataSource6" DataTextField="INSTANCE" DataValueField="INSTANCE"
I get an error:
"DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'INSTANCE'."
If I remove the "SelectedValue..." I get the error:
Cannot insert the value NULL into column 'DB2_DSN', table 'xxx.dbo.PROCESS'; column does not allow nulls. UPDATE fails.
The statement has been terminated.
I also tried using the DataBind() but it also gives me an error.
The other value (FTP_IND) works fine because it is listed/hardcoded.
Why does it work for FTP_IND and not for DB2_DSN?
First:
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:xxxConnectionString2 %>"
DeleteCommand="DELETE FROM PROCESS WHERE NAME = #NAME AND ENVIRONMENT = #ENVIRONMENT"
SelectCommand="SELECT * FROM [PROCESS]"
UpdateCommand="UPDATE PROCESS SET ENVIRONMENT = #ENVIRONMENT, PROCESS_STATUS = #PROCESS_STATUS, IC_VALUE = #IC_VALUE,
FTP_IND = #FTP_IND, DB2_DSN = #DB2_DSN, DB2_REGION = #DB2_REGION,
ALERT_EMAIL = #ALERT_EMAIL, NOTIFY_EMAIL = #NOTIFY_EMAIL, DEBUG_INFO = #DEBUG_INFO,
LAST_UPDATE_DATE = CURRENT_TIMESTAMP, LAST_UPDATE_USERID = #UID, LAST_UPDATE_IP = #UIP WHERE (NAME = #NAME)">
<UpdateParameters>
<asp:SessionParameter Name="UID" SessionField="User_ID" Type="String" />
<asp:SessionParameter Name="UIP" SessionField="User_IP" Type="String" />
<asp:Parameter Name="ENVIRONMENT" />
<asp:Parameter Name="PROCESS_STATUS" />
<asp:Parameter Name="IC_VALUE" />
<asp:Parameter Name="FTP_IND" />
<asp:Parameter Name="DB2_DSN" />
<asp:Parameter Name="DB2_REGION" />
<asp:Parameter Name="ALERT_EMAIL" />
<asp:Parameter Name="NOTIFY_EMAIL" />
<asp:Parameter Name="DEBUG_INFO" />
<asp:Parameter Name="NAME" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource6" runat="server"
ConnectionString="<%$ ConnectionStrings:xxxConnectionString2 %>"
SelectCommand="SELECT [INSTANCE] FROM [DB2_INSTANCES] ORDER BY [INSTANCE] ASC">
</asp:SqlDataSource>
Second:
<asp:TemplateField HeaderText="FTP" SortExpression="FTP_IND">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList5" runat="server"
SelectedValue='<%# Bind("FTP_IND") %>'
ToolTip="Use this to turn off and on the FTP process" Font-Size="Small">
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("FTP_IND") %>'
ToolTip="Indicates if FTP will take place" Font-Size="Small">
</asp:Label>
</ItemTemplate>
<ItemStyle Font-Size="Small" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText = "DB2 Instance" SortExpression="DB2_DSN">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList6" runat="server"
ToolTip="Use this to choose the DB2 Instance" Font-Size="Small"
DataSourceID="SqlDataSource6"
DataTextField="INSTANCE"
DataValueField="INSTANCE">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("DB2_DSN") %>'
ToolTip="Indicates the DB2 Instance being used" Font-Size="Small">
</asp:Label>
</ItemTemplate>
<ItemStyle Font-Size="Small" HorizontalAlign="Center" />

Gridview Error on editing with dropdownlist

I have grid view with folowing complete code With Msaccess DB.I have used the decode function in sql query.When i press the edit button on grid view it shows folowing error
"DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
My SQL Data source code is below
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataConnectionString2 %>"
DeleteCommand="DELETE FROM [EMAILS] WHERE [ID] = ?" InsertCommand="INSERT INTO [EMAILS] ([Email], [FULLNAME],[FLAG]) VALUES (?, ?, ?)"
ProviderName="<%$ ConnectionStrings:DataConnectionString2.ProviderName %>" SelectCommand="SELECT ID, Email, FULLNAME, switch(FLAG = 1, 'Allowed', Flag = 0, 'Not Allowed') AS FLAG FROM EMAILS"
UpdateCommand="UPDATE [EMAILS] SET [Email] = ?, [FULLNAME] = ?,[FLAG] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FULLNAME" Type="String" />
<asp:Parameter Name="FLAG" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
And Grid View Code is bellow
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" DataKeyNames="ID" DataSourceID="SqlDataSource1"
HorizontalAlign="Center" Width="821px" EmptyDataText="No Emails Found">
<RowStyle BackColor="White" Font-Names="Arial" Font-Size="Small" ForeColor="Black" />
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True" ShowSelectButton="True" ShowDeleteButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="FULLNAME" HeaderText="Full Name" SortExpression="FULLNAME" />
<asp:TemplateField HeaderText="Flag" SortExpression="FLAG">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue="<%# Bind('FLAG') %>" AppendDataBoundItems="True">
<asp:ListItem Value="1">Allowed</asp:ListItem>
<asp:ListItem Value="0">Not Allowed</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FLAG") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" Font-Names="Arial" Font-Size="Small"
ForeColor="#FFFFCC" HorizontalAlign="Center" />
<EmptyDataRowStyle BackColor="#804000" Font-Names="Arial" Font-Size="Small" ForeColor="White" />
</asp:GridView>
Please tell me what possible error is here
Check weather the value in Field flag of the row you are trying to edit, is available in the DropDownList in EditItemTemplate
And try removing AppendDataBoundItems="True" in DropDownList in EditItemTemplate

Resources