file-griddate.aspx
<div>
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:CommandField HeaderText="Edit This" ShowEditButton="true" ButtonType="Button" />
<asp:TemplateField HeaderText="DATE">
<itemtemplate>
<asp:Label runat="server" Text='<%# Bind("date") %>' ID="date"></asp:Label><br />
</itemtemplate>
<EditItemTemplate>
<asp:Calendar ID="Cal1" runat="server" BackColor="White"
BorderColor="#999999" CellPadding="0" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="50px" ="false"
Visible="True" Width="47px" SelectedDate='<%# Bind("date") %>'>
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<SelectorStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#FFFFCC" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<OtherMonthDayStyle ForeColor="#808080" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
</asp:Calendar>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testingConnectionString %>"
SelectCommand="SELECT * FROM [mytest]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
this is my vb code
Imports System.Data.SqlClient
Partial Class griddate
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dr As SqlDataReader
Dim st As String = ConfigurationManager.ConnectionStrings("testingConnectionString").ToString
Dim con As New Data.SqlClient.SqlConnection(st)
con.Open()
Dim q As String = "select * from mytest"
Dim com As New Data.SqlClient.SqlCommand(q, con)
com.ExecuteNonQuery()
dr = com.ExecuteReader()
If dr.HasRows() Then
GridView1.DataSource = dr
GridView1.DataBind()
End If
con.Close()
End Sub
Private Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
End Sub
Private Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Try
Dim st As String = ConfigurationManager.ConnectionStrings("testingConnectionString").ToString
Dim con As New Data.SqlClient.SqlConnection(st)
con.Open()
Dim com As SqlCommand
Dim RowinDex As TableCell
RowinDex = GridView1.Rows(e.RowIndex).Cells(0)
Dim idate As String = CType(RowinDex.FindControl("datedrop"), Calendar).SelectedDate
com = New SqlCommand("Update mytest Set [date]='" & idate & "' Where [date]='" & GridView1.DataKeys(e.RowIndex).Value & "'", con)
com.ExecuteNonQuery()
Dim dr As SqlDataReader
Dim q As String = " select * mytets where date = '" & idate & "' "
Dim comm As New Data.SqlClient.SqlCommand(q, con)
dr = comm.ExecuteReader()
If dr.HasRows() Then
GridView1.DataSource = dr
GridView1.DataBind()
GridView1.Visible = True
End If
con.Close()
Catch ex As Exception
Response.Write("<script>alert('" & ex.Message & "')</script>")
End Try
End Sub
WHEN I CLICK ON EDIT IN GRID I GOT THIS ERROR
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
CAN ANYBODY HELP ME