应该也可以定义CommandName在itemcommand里激发
解决方案 »
- 如何把UrlRewriter重写规则存放另一个config文件
- IIS发布网页后 连接主机的数据库 但是我需要的表在sqlserver2000上 但是在IIS上发布后 总是连接在sqlserver2005上去
- javascript 绑定服务器控件 事件
- owc11如何设置Range区域的值
- 无法创建大小为 8103 的行,该值大于允许的最大值 8060。
- 关于2个页面之间的数据输入与数据绑定问题?
- 跪求vs2003中TreeView教程或者示例
- 网页播放器的问题
- knockout-js问题
- 简单 的问题
- 我想问在datagrid中,如何实现选定某条记录,将访记录行的底色转为指定的颜色
- 如何打印DataGrid控件中当前显示的内容?
private void WebDataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//add event for DropDownList Select Change
if(e.Item.ItemType==ListItemType.EditItem)
{
((DropDownList)(e.Item.Cells[x].Controls[1])).SelectedIndexChanged+=new System.EventHandler(this.DropDownListName_SelectedIndexChanged);
}
}
然后撰写这个代理事件实现的代码:
private void DropDownName_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (DropDownListName.SelectedItem.Value.Equals("2"))
{
DropDownListName.Items.Clear();
//要实现的操作.
}
}
然后善用ViewState就差不多了.自己看看吧~~~
private void WebDataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//add event for DropDownList Select Change
if(e.Item.ItemType==ListItemType.EditItem)
{
((DropDownList)(e.Item.Cells[x].Controls[1])).SelectedIndexChanged+=new System.EventHandler(this.DropDownListName_SelectedIndexChanged);
}
}
然后撰写这个代理事件实现的代码:
private void DropDownName_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (DropDownListName.SelectedItem.Value.Equals("2"))
{
DropDownListName.Items.Clear();
//要实现的操作.
}
}
然后善用ViewState就差不多了.自己看看吧~~~
****************************************************
<asp:TemplateColumn HeaderText="column1">
<ItemTemplate><asp:DropDownList id="DropDownList1" DataSource =<%#getDataSource("DropDownList1") %> DataTextField ='key' DataValueField ='value' runat="server" Width="134px">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn><asp:TemplateColumn HeaderText="column2">
<ItemTemplate><asp:DropDownList id="DropDownList2" DataSource =<%#getDataSource("DropDownList2") %> DataTextField ='key' DataValueField ='value' runat="server" Width="142px">
</asp:DropDownList></ItemTemplate>
</asp:TemplateColumn>
.aspx.vb
************************************************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在這裡放置使用者程式碼以初始化網頁
Page.DataBind()
End Sub
Protected Function getDataSource(ByVal id As String) As DataTable Dim DT As DataTable
Dim DR As DataRow
DT = New DataTable("DT")
DT.Columns.Add("key", GetType(String))
DT.Columns.Add("value", GetType(String)) DR = DT.NewRow
Dim strSQL As String = GetSqlString(id)
If conn.State <> ConnectionState.Open Then conn.Open()
Dim sqlDBcmd As SqlCommand = New SqlCommand
sqlDBcmd.Connection = conn
sqlDBcmd.CommandText = strSQL
Dim DBreader As SqlDataReader = sqlDBcmd.ExecuteReader()
While DBreader.Read()
DR(0) = DBreader.Item(0)
DR(1) = DBreader.Item(1)
DT.Rows.Add(DR)
DR = DT.NewRow
End While
DBreader.Close() Return DT
DT.Dispose() End Function Protected Function GetSqlString(ByVal controlID As String) As String
Dim str As String
'在此出添加不同dropdownlist的sql語句就好了
Select Case controlID
Case "dropdownlist1"
str =""
case "dropdownlist2"
str =""
End Select Return str
End Function
******************************************************
将 dropdownlist1的autopostback设为true ,一切搞定
DataSource ='<%#getDataSource("DropDownList1") %>'
单引号是必不可少的
CType(e.Item.Cells(2).Controls(1), Texmicro.WebControls.DropDownList).SelectedIndexChanged = AddressOf Me.DropDownListName_SelectedIndexChanged抱错啊。
If (e.Item.ItemType = ListItemType.Footer And sender.ShowFooter = True) Then
AddHandler CType(e.Item.Cells(2).Controls(1), Texmicro.WebControls.DropDownList).SelectedIndexChanged, AddressOf Me.DropDownListName_SelectedIndexChanged
End If
End Sub