当单击gridview上的编辑按钮时,Gridview不会显示 [英] When clicking edit button on gridview the Gridview doesnt show up
问题描述
我在这里遇到了问题.香港专业教育学院创建了一个gridvew我要更新为真实.我的问题是,当我按下编辑"按钮时,Gridview会隐藏(我认为),除非我再次通过下拉列表进行搜索(我创建了一个下拉列表,因为我只希望查看特定数据)并且返回到先前的网格状态现在可以随时进行更新了
是否缺少任何代码?
请帮助
这是我的代码:
来源
hi guys, ive got a problem here. ive created a gridvew where i want updating to be true. my problem is when i hit the edit button the gridview hides(i think) unless i search in again through my drop down list (ive created a dropdownlist because i only want specific data to be viewed) and when i return to my previous grid state now the it is ready to be updated
is there any missing codes?
plss help
here is my code:
On source
<pre lang="xml"><asp:GridView ID="TPdataCCXXXXX" runat="server" Height="439px" Width="854px" AutoGenerateColumns="False"
onrowcancelingedit="TPdataCCXXXXX_RowCancelingEdit"
onrowediting="TPdataCCXXXXX_RowEditing" onrowupdating="TPdataCCXXXXX_RowUpdating">
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true" />
<asp:TemplateField HeaderText="CourseTitle">
<ItemTemplate>
<%#Eval("CourseTitle")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtCourseTitle" Text=''<%# Eval("CourseTitle")%>'' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CourseCode">
<ItemTemplate>
<%#Eval("CourseCode")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtCourseCode" Text=''<%# Eval("CourseCode")%>'' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Objectives">
<ItemTemplate>
<%#Eval("Objectives")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtObjectives" Text=''<%# Eval("Objectives")%>'' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Duration">
<ItemTemplate>
<%#Eval("Duration")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtDuration" Text=''<%# Eval("Duration")%>'' />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
在我的VB代码中
on my VB codes
<pre lang="vb">Imports System.Web
Imports System
Imports System.Data
Partial Class updateTP
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If drpcc.Text = "CCXXXXX" Then
Dim strSQL As String
Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)"
connection.Open()
Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
TPdataCCXXXXX.DataSource = myCommand.ExecuteReader()
TPdataCCXXXXX.DataBind()
ElseIf drpcc.Text = "123" Then
Dim strSQL As String
Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)"
connection.Open()
Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
TPdataCCXXXXX.DataSource = myCommand.ExecuteReader()
TPdataCCXXXXX.DataBind()
End If
End Sub
Protected Sub TPdataCCXXXXX_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles TPdataCCXXXXX.RowUpdating
Dim row As GridViewRow = TPdataCCXXXXX.Rows(e.RowIndex)
Dim txtCourseTitle As TextBox = row.FindControl("txtCourseTitle")
Dim txtCourseCode As TextBox = row.FindControl("txtCourseCode")
Dim txtObjectives As TextBox = row.FindControl("txtObjectives")
Dim txtDuration As TextBox = row.FindControl("txtDuration")
End Sub
Protected Sub TPdataCCXXXXX_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles TPdataCCXXXXX.RowEditing
TPdataCCXXXXX.EditIndex = e.NewEditIndex
TPdataCCXXXXX.DataBind()
End Sub
Protected Sub TPdataCCXXXXX_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles TPdataCCXXXXX.RowCancelingEdit
TPdataCCXXXXX.EditIndex = -1
TPdataCCXXXXX.DataBind()
End Sub
在此先感谢并提供了更多的功能
Thanks in advance and more power
推荐答案
它看起来是基于对"drpcc"的选择来绑定网格,所以我认为问题出在drpcc的绑定.因为drpcc的选择可能会更改,并且不会进入任何条件,例如drpcc.Text ="CCXXXXX"等.
It is looking that you are binding the grid based on the selection of the "drpcc", So I think the problem is with the binding of the drpcc. Because the selection might changed of the drpcc and it is not going into any of the condition e.g. drpcc.Text = "CCXXXXX" and other.
您不需要任何if..else代码块,即
You don''t need any if..else block in your code block i.e.
If drpcc.Text = "CCXXXXX" Then...
因为IF和ELSE IF相同,并且
because the IF and ELSE IF are identical and the
myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
无论如何都使用drpcc.Text,即下拉菜单的当前值.
谢谢,
Hemant
anyway taking drpcc.Text i.e. current value of your drop down.
thanks,
Hemant
感谢nit_singh爵士
我发现了错误,我创建了另一个名为BindGrid的子程序,这就是我在编辑事件中调用的内容
Thanks Sir nit_singh
Ive found the error, ive created another sub named BindGrid and thats what im calling on my editing events
<pre lang="vb">Protected Sub TPdataCCXXXXX_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles TPdataCCXXXXX.RowEditing
TPdataCCXXXXX.EditIndex = e.NewEditIndex
BindGrid()
End Sub
Protected Sub TPdataCCXXXXX_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles TPdataCCXXXXX.RowCancelingEdit
TPdataCCXXXXX.EditIndex = -1
BindGrid()
End Sub
Public Sub BindGrid()
If drpcc.Text = "CCXXXXX" Then
Dim strSQL As String
Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)"
connection.Open()
Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
TPdataCCXXXXX.DataSource = myCommand.ExecuteReader()
TPdataCCXXXXX.DataBind()
ElseIf drpcc.Text = "123" Then
Dim strSQL As String
Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)"
connection.Open()
Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
TPdataCCXXXXX.DataSource = myCommand.ExecuteReader()
TPdataCCXXXXX.DataBind()
End If
End Sub
这篇关于当单击gridview上的编辑按钮时,Gridview不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!