当我单击网格n中的编辑时,我希望在网格中的日历中选择日期列值,这使我可以更改日期n,然后我可以先更改日期,然后更改up [表中的日期 [英] i want date column value selected in calender in grid when i click edit in grid n which allows me to change date n then i can change date then up[date in table

查看:87
本文介绍了当我单击网格n中的编辑时,我希望在网格中的日历中选择日期列值,这使我可以更改日期n,然后我可以先更改日期,然后更改up [表中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

file-griddate.aspx

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>



这是我的vb代码



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
         ''ópening
         Dim st As String = ConfigurationManager.ConnectionStrings("testingConnectionString").ToString
         Dim con As New Data.SqlClient.SqlConnection(st)
         con.Open()
         ''command
         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



当我单击网格"中的编辑时,出现此错误

无法加载viewstate.加载视图状态的控制树必须与在上一个请求期间用于保存视图状态的控制树匹配.例如,当动态添加控件时,在回发期间添加的控件必须与在初始请求期间添加的控件的类型和位置匹配.



谁能帮助我



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

推荐答案

ConnectionStrings:testingConnectionString %> " span> =" 选择*来自[mytest]" < /asp:SqlDataSource > < /div > < /form > < /body > < /html >
ConnectionStrings:testingConnectionString %>" SelectCommand="SELECT * FROM [mytest]"></asp:SqlDataSource> </div> </form> </body> </html>



这是我的vb代码



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
         ''ópening
         Dim st As String = ConfigurationManager.ConnectionStrings("testingConnectionString").ToString
         Dim con As New Data.SqlClient.SqlConnection(st)
         con.Open()
         ''command
         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



当我单击网格"中的编辑时,出现此错误

无法加载viewstate.加载视图状态的控制树必须与在上一个请求期间用于保存视图状态的控制树匹配.例如,当动态添加控件时,在回发期间添加的控件必须与在初始请求期间添加的控件的类型和位置匹配.



谁能帮助我



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


也许以下内容可以帮助您:
http://blog.typps.com/2008/01/failed-to- load-viewstate-typical.html [ ^ ]
http://stackoverflow.com/questions/580704/failed-to-load-viewstate-happening-only-偶尔偶尔很难重新创建 [ http://www.codeguru.com/forum/showthread.php?t=371749 [ ^ ]
Maybe the following can help:
http://blog.typps.com/2008/01/failed-to-load-viewstate-typical.html[^]
http://forums.asp.net/t/1295517.aspx/1?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+[^]
http://stackoverflow.com/questions/580704/failed-to-load-viewstate-happening-only-occassionally-tough-to-recreate[^]
http://www.codeguru.com/forum/showthread.php?t=371749[^]


这篇关于当我单击网格n中的编辑时,我希望在网格中的日历中选择日期列值,这使我可以更改日期n,然后我可以先更改日期,然后更改up [表中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆