上次的帖子请参考
http://community.csdn.net/Expert/topic/3780/3780873.xml?temp=.5147058精简代码如下:
team.apsx
==============
<%@ Page Language="VB" Trace="false" Inherits="BWSLib.TeamPage" src="Team.vb" AutoEventWireUp="false" %>
<%@ Register TagPrefix="expo" Namespace="BWSLib.Controls" Assembly="MyEditableGrid" %>
<HTML>
<script language="javascript" src="../js/StringTrim.js"></script>
<script language="javascript" src="../js/ServerDropDownList.js"></script>
</HEAD>
<body MS_POSITIONING="flowLayout" bgcolor="ivory" link="blue" vlink="blue">
<form id="Form1" method="post" runat="server">
<asp:Image id="Image1" runat="server" ImageUrl="../Img/log.gif"></asp:Image><BR>
<strong>Team Management</strong><BR>
<asp:TextBox ID="DepartmentIDtxt" Runat="server" style="display:none;"></asp:TextBox>Country:
<asp:DropDownList id="DropDownList1" runat="server" />
Office :
<asp:DropDownList id="DropDownList2" runat="server" />
Department :
<asp:DropDownList id="DropDownlist3" runat="server" autopostback="true" /><expo:MyEditableGrid id="grid" runat="server" AutoGenerateColumns="false" PageSize="10" DataKeyField="TEAM_ID" BorderWidth="1" GridLines="both" OnInitRow="InitRow" OnUpdateView="UpdateView" OnSaveData="SaveData" OnInsertData="InsertData" OnDeleteData="DeleteData">
<COLUMNS>
<ASP:BOUNDCOLUMN runat="server" headertext="ID" datafield="TEAM_ID" readonly="true" />
<ASP:BOUNDCOLUMN runat="server" headertext="Team" datafield="TEAM_CODE" />
<ASP:BOUNDCOLUMN runat="server" headertext="Department" readonly="true" datafield="DEPARTMENT_CODE" />
</COLUMNS>
<PAGERSTYLE font-name="webdings" PrevPageText="3" NextPageText="4" />
</expo:MyEditableGrid>
<asp:linkbutton runat="server" Text="Insert" onclick="OnInsert" id="Linkbutton1" />
</form>
<script language="javascript">
<!--
//处理 当前页面 级联dropdownlist的javascript脚本
var ObjDepartmentTxt=document.getElementById("DepartmentIDtxt");
var ObjDrlist1=document.all.DropDownList1;
var ObjDrlist2=document.all.DropDownList2;
var ObjDrlist3=document.all.DropDownlist3;
var DropList1='<%=Request.Form("DropDownList1")%>' ;
var DropList2='<%=Request.Form("DropDownList2")%>' ;
var DropList3='<%=Request.Form("DropDownList3")%>' ;
DropList1=DropList1.trim();
DropList2=DropList2.trim();
DropList3=DropList3.trim();
if (DropList1!='' && DropList2!=''){
var Drop1=parseInt(DropList1);
var Drop2=parseInt(DropList2)-1;
load(Drop1,'DropDownList2');
ObjDrlist2.options[Drop2].selected=true; }if (DropList2!='' && DropList3!=''){
DropList2=parseInt(DropList2);
DropList3=parseInt(DropList3)-1;
load(DropList2,'DropDownList3');
ObjDrlist3.options[DropList3].selected=true;
ObjDepartmentTxt.value=DropList3+1} if (DropList1=='' && DropList2==''&& DropList3=='') {
var CountrySel=ObjDrlist1.options[ObjDrlist1.selectedIndex].value;
load(CountrySel,'DropDownList2');
var OfficeSel=ObjDrlist2.options[ObjDrlist2.selectedIndex].value;
load(OfficeSel,'DropDownList3'); }
//缺省情况下 如果当前Office下没有Department选项就将ObjDepartmentTxt.value=0
if (ObjDrlist3.length==0) { ObjDepartmentTxt.value=0;
} else { ObjDepartmentTxt.value=ObjDrlist3.options[ObjDrlist3.selectedIndex].value; }function CheckDropDownlist(t,strDrop){ if (t==0 && strDrop=="DropDownList3") { ObjDepartmentTxt.value=0; } }
//-->
</script>
</body>
</HTML>
http://community.csdn.net/Expert/topic/3780/3780873.xml?temp=.5147058精简代码如下:
team.apsx
==============
<%@ Page Language="VB" Trace="false" Inherits="BWSLib.TeamPage" src="Team.vb" AutoEventWireUp="false" %>
<%@ Register TagPrefix="expo" Namespace="BWSLib.Controls" Assembly="MyEditableGrid" %>
<HTML>
<script language="javascript" src="../js/StringTrim.js"></script>
<script language="javascript" src="../js/ServerDropDownList.js"></script>
</HEAD>
<body MS_POSITIONING="flowLayout" bgcolor="ivory" link="blue" vlink="blue">
<form id="Form1" method="post" runat="server">
<asp:Image id="Image1" runat="server" ImageUrl="../Img/log.gif"></asp:Image><BR>
<strong>Team Management</strong><BR>
<asp:TextBox ID="DepartmentIDtxt" Runat="server" style="display:none;"></asp:TextBox>Country:
<asp:DropDownList id="DropDownList1" runat="server" />
Office :
<asp:DropDownList id="DropDownList2" runat="server" />
Department :
<asp:DropDownList id="DropDownlist3" runat="server" autopostback="true" /><expo:MyEditableGrid id="grid" runat="server" AutoGenerateColumns="false" PageSize="10" DataKeyField="TEAM_ID" BorderWidth="1" GridLines="both" OnInitRow="InitRow" OnUpdateView="UpdateView" OnSaveData="SaveData" OnInsertData="InsertData" OnDeleteData="DeleteData">
<COLUMNS>
<ASP:BOUNDCOLUMN runat="server" headertext="ID" datafield="TEAM_ID" readonly="true" />
<ASP:BOUNDCOLUMN runat="server" headertext="Team" datafield="TEAM_CODE" />
<ASP:BOUNDCOLUMN runat="server" headertext="Department" readonly="true" datafield="DEPARTMENT_CODE" />
</COLUMNS>
<PAGERSTYLE font-name="webdings" PrevPageText="3" NextPageText="4" />
</expo:MyEditableGrid>
<asp:linkbutton runat="server" Text="Insert" onclick="OnInsert" id="Linkbutton1" />
</form>
<script language="javascript">
<!--
//处理 当前页面 级联dropdownlist的javascript脚本
var ObjDepartmentTxt=document.getElementById("DepartmentIDtxt");
var ObjDrlist1=document.all.DropDownList1;
var ObjDrlist2=document.all.DropDownList2;
var ObjDrlist3=document.all.DropDownlist3;
var DropList1='<%=Request.Form("DropDownList1")%>' ;
var DropList2='<%=Request.Form("DropDownList2")%>' ;
var DropList3='<%=Request.Form("DropDownList3")%>' ;
DropList1=DropList1.trim();
DropList2=DropList2.trim();
DropList3=DropList3.trim();
if (DropList1!='' && DropList2!=''){
var Drop1=parseInt(DropList1);
var Drop2=parseInt(DropList2)-1;
load(Drop1,'DropDownList2');
ObjDrlist2.options[Drop2].selected=true; }if (DropList2!='' && DropList3!=''){
DropList2=parseInt(DropList2);
DropList3=parseInt(DropList3)-1;
load(DropList2,'DropDownList3');
ObjDrlist3.options[DropList3].selected=true;
ObjDepartmentTxt.value=DropList3+1} if (DropList1=='' && DropList2==''&& DropList3=='') {
var CountrySel=ObjDrlist1.options[ObjDrlist1.selectedIndex].value;
load(CountrySel,'DropDownList2');
var OfficeSel=ObjDrlist2.options[ObjDrlist2.selectedIndex].value;
load(OfficeSel,'DropDownList3'); }
//缺省情况下 如果当前Office下没有Department选项就将ObjDepartmentTxt.value=0
if (ObjDrlist3.length==0) { ObjDepartmentTxt.value=0;
} else { ObjDepartmentTxt.value=ObjDrlist3.options[ObjDrlist3.selectedIndex].value; }function CheckDropDownlist(t,strDrop){ if (t==0 && strDrop=="DropDownList3") { ObjDepartmentTxt.value=0; } }
//-->
</script>
</body>
</HTML>
team.vb 服务端datagrid处理如下:
====================================
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Text
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports BWSLib.Controls
Imports System.ConfigurationNamespace BWSLib
Public Class TeamPage
Inherits Page
Protected m_connString As String
Protected m_connStr As String
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList3 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DepartmentIDtxt As System.Web.UI.WebControls.TextBox
Protected grid As MyEditableGrid
Protected WithEvents Linkbutton1 As System.Web.UI.WebControls.LinkButton
Dim DepartmentIDParam
Dim OPcmd As String ' Page OnLoad
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
m_connString = ConfigurationSettings.AppSettings("CRMSQLOLEDBStrconn")
OPcmd = ""
If Not IsPostBack Then
'Fill DropDownList1 data
Bindlist(DropDownList1, "COUNTRY_CODE", "COUNTRY_ID", "Select * From COUNTRY_TAB")
DepartmentIDParam = 1
DataFromSourceToMemory(DepartmentIDParam)
UpdateDataView()
Else
DepartmentIDParam = Request.Form("DropDownList3")
DataFromSourceToMemory(DepartmentIDParam)
UpdateDataView()
End If
End Sub Private Sub DropDownList3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
DepartmentIDParam = DropDownList3.SelectedValue
DataFromSourceToMemory(DepartmentIDParam)
UpdateDataView()
End Sub Private Function Get_DropDownList3Value()
DepartmentIDParam = DepartmentIDtxt.Text
End Function ' DataFromSourceToMemory
Private Sub DataFromSourceToMemory(ByVal idstr As Integer)
' Gets rows from the data source
Dim oDS As DataSet = PhysicalDataRead(idstr)
' Stores it in the Cache cache
Cache("MyData") = oDS
End Sub
' PhysicalDataRead
Private Function PhysicalDataRead(ByVal idstr As Integer) As DataSet
' Command and connection string
Dim strCmd As String = "SELECT * FROM TEAM_TAB,DEPARTMENT_TAB WHERE EAM_TAB.TEAM_DEPARTMENTID=DEPARTMENT_TAB.DEPARTMENT_ID AND DEPARTMENT_TAB.DEPARTMENT_ID= " & idstr
Dim da As OleDbDataAdapter = New OleDbDataAdapter(strCmd, m_connString)
Dim ds As DataSet = New DataSet
da.Fill(ds, "TEAM_TAB") Return ds
End Function
' Returns data
Private Function GetData() As DataView
' Retrieves the data
Dim ds As DataSet = CType(Cache("MyData"), DataSet)
Dim dv As DataView = ds.Tables("TEAM_TAB").DefaultView
Return dv
End Function ' Refresh the UI
Private Sub UpdateDataView()
grid.DataSource = GetData()
ProcessCurrentPageInt(OPcmd)
grid.DataBind()
End Sub ''''''''''' EVENT HANDLERS
' EVENT HANDLER: SaveData
Public Sub SaveData(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim sb As StringBuilder = New StringBuilder("")
Get_DropDownList3Value()
sb.Append("UPDATE TEAM_TAB SET ")
sb.Append("TEAM_CODE='{0}'")
sb.Append(" WHERE TEAM_ID={1}")
Dim cmd As String = sb.ToString()
Dim TeamCode As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
cmd = String.Format(cmd, TeamCode.Text, grid.DataKeys(e.Item.ItemIndex))
' Executes the command
Dim conn As OleDbConnection = New OleDbConnection(m_connString)
Dim c As OleDbCommand = New OleDbCommand(cmd, conn)
c.Connection.Open()
c.ExecuteNonQuery()
c.Connection.Close()
DataFromSourceToMemory(DepartmentIDParam)
End Sub
' EVENT HANDLER: InsertData
Public Sub InsertData(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim sb As StringBuilder = New StringBuilder("")
Get_DropDownList3Value()
sb.Append("INSERT INTO TEAM_TAB (TEAM_CODE, TEAM_DEPARTMENTID) VALUES(")
sb.Append("'{0}', {1})")
Dim cmd As String = sb.ToString() Dim TeamCode As TextBox = CType(e.Item.Cells(1).Controls(0), TextBox)
cmd = String.Format(cmd, TeamCode.Text, DepartmentIDParam)
' Executes the command
Dim conn As OleDbConnection = New OleDbConnection(m_connString)
Dim c As OleDbCommand = New OleDbCommand(cmd, conn)
c.Connection.Open()
c.ExecuteNonQuery()
c.Connection.Close()
DataFromSourceToMemory(DepartmentIDParam)
End Sub
' EVENT HANDLER: DeleteData
Public Sub DeleteData(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Get_DropDownList3Value()
OPcmd = "DELETE"
Dim cmd As String = "DELETE FROM TEAM_TAB WHERE TEAM_ID={0}"
cmd = String.Format(cmd, grid.DataKeys(e.Item.ItemIndex))
' Executes the command
Dim conn As OleDbConnection = New OleDbConnection(m_connString)
Dim c As OleDbCommand = New OleDbCommand(cmd, conn)
c.Connection.Open()
c.ExecuteNonQuery()
c.Connection.Close()
ProcessCurrentPageInt("DELETE")
DataFromSourceToMemory(DepartmentIDParam)
End Sub ' EVENT HANDLER: OnInsert
Public Sub OnInsert(ByVal sender As Object, ByVal e As EventArgs)
OPcmd = "INSERT"
grid.AddNewRow = True
UpdateDataView()
End Sub ' EVENT HANDLER: InitRow
Public Sub InitRow(ByVal sender As Object, ByVal e As DataGridInitRowEventArgs)
e.Row("DEPARTMENT_CODE") = " "
End Sub ' EVENT HANDLER: UpdateView
Public Sub UpdateView(ByVal sender As Object, ByVal e As EventArgs)
OPcmd = "UPDATE"
UpdateDataView()
End Sub Private Sub InitializeComponent()
End Sub 'LOAD DropDownList context
Private Sub Bindlist(ByVal T As DropDownList, ByVal nameParam As String, ByVal valueParam As String, ByVal SQLStr As String)
Dim MyConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("CRMStrconn"))
Dim MySqlCommand As SqlDataAdapter = New SqlDataAdapter(SQLStr, MyConnection)
Dim ds As DataSet = New DataSet
MySqlCommand.Fill(ds, nameParam)
T.DataSource = ds.Tables(nameParam).DefaultView
T.DataTextField = nameParam
T.DataValueField = valueParam
T.DataBind()
T.Attributes.Add("onchange", "load(this.value,'DropDownList2')")
DropDownList2.Attributes.Add("onchange", "load(this.value,'DropDownList3')")
End Sub Private Sub ProcessCurrentPageInt(ByVal paramGrid As String)
Select Case paramGrid
Case "DELETE"
'当删除数据库中数据并在数据绑定之前,判断是否需要翻页,以纠正 CurrentPageIndex的错误。
If grid.Items.Count = 1 And grid.CurrentPageIndex > 0 Then
grid.CurrentPageIndex = grid.CurrentPageIndex - 1
end if
Case "UPDATE"
Case "INSERT"
If grid.Items.Count = 1 And grid.CurrentPageIndex > 0 Then
grid.CurrentPageIndex = grid.CurrentPageIndex + 1
Else
grid.CurrentPageIndex = 0
End If
Case "FANYE" End Select
End Sub
End Class
End Namespace
1> 我在更新数据时 如
id team department
1 FSE SZHLOGFSE [Edit] [Delete]
[Insert]
当我点'Edit',修改FSE为FSEAA在提交时发现得到得还是FSE而不是FSEAA
2> 当我点'Insert' 填写完数据后提交,没有任何数据被插入,
其实我在做Department页面时都没有问题,team页面只是由二级级联变成三级级联,
(但是级联的操作仍然正常,只是team.vb中对数据的操作不知哪里出现了逻辑上的问题)
3 在第三个下拉列表(即DropDownList3 ),选定一个选项后当前页面刷新后,我在当前的
DropDownlist3的选项的情况下,点'Insert'按钮,并填完数据后提交,与第2个问题一样
奇怪的是当我选择DropDownList3第一个选项后,发现在该选项下的第一行却处于编辑状态
===================================================================================
各位兄台,恳请帮我解决一下,搞定献上200分,以表感谢
代码有点长,小弟才疏学浅,还望大家不吝指点
'Fill DropDownList1 data
Bindlist(DropDownList1, "COUNTRY_CODE", "COUNTRY_ID", "Select * From COUNTRY_TAB")
DepartmentIDParam = 1
DataFromSourceToMemory(DepartmentIDParam)
UpdateDataView()
Else
DepartmentIDParam = Request.Form("DropDownList3")
DataFromSourceToMemory(DepartmentIDParam)'下面这行去掉
UpdateDataView()End If中的最后一个UpdateDataView()去掉,然后把这个方法放到其他的操作方法中,比如在 Insert或edit 的方法里最后一行调用,比如Public Sub InsertData(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
....................................................
c.Connection.Close()
DataFromSourceToMemory(DepartmentIDParam)'这个位置绑定DataGrid
UpdateDataView()End Sub
但是我在改变DropDownlist3选项后 需要updataview()来刷新记录,否则就显示结果还是前一个选
项(department)所对应的team 记录
你方法用有效,虽然没有完全搞定,但我想想就会搞定了,谢谢你
你去外前面的帖子回一下,随便回一下就可以,我把200份全给你
解决了这个问题我剩下来的事情就好办了,