急。。datagrid得(DropDownList模板列?下班揭帖。。。 我要在datagrid里加上(DropDownList模板列,在(DropDownList发生选择时,更改数据库?请教asp.net和c#怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://community.csdn.net/Expert/topic/3506/3506615.xml?temp=.3441889 <%@ Page language="c#" Codebehind="DataGrid.aspx.cs" AutoEventWireup="false" Inherits="ReadWord.DataGrid" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>DataGrid</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:DataGrid Runat="server" id="DataGrid1" ShowFooter="True"> <Columns> <asp:TemplateColumn> <FooterTemplate> <asp:DropDownList Runat="server" ID="myDropDownList" AutoPostBack="True"> <asp:ListItem Value="1">test1</asp:ListItem> <asp:ListItem Value="2">test2</asp:ListItem> </asp:DropDownList> </FooterTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> </form> </body></HTML> 刚做过 #region 更新数据 public void update1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { string t1=((DropDownList)e.Item.FindControl("yourDropDownListname")).SelectedValue; conn.Open(); cmd = new SqlCommand(sql,conn); cmd.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; list(); } #endregion 我用下面得方法 System.Web.UI.WebControls.DropDownList myList; myList=(DropDownList)e.Item.Cells[0].Controls[0].FindControl("myDropDownList"); myList.SelectedIndexChanged +=new EventHandler(myList_SelectedIndexChanged); }提示:未将对象引用设置到对象的实例。这是什么问题? 可以做到。。首先你在你的datagrid放了个dropdownlist对吧。现在我就只写dropdownlist的代码就好。恩<asp:DropDownList ID="ddl" Runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="True"><asp:ListItem Value="0" text="男"></asp:ListItem><asp:ListItem Value="1" text="女"></asp:ListItem></asp:DropDownList>注意。这里设置了AutoPostBack属性为True.还定义了dropdownlist的SelectedINdexChanged事件。恩。你会说。这个是潜逃在datagrid里的。那怎么找到dropdownlist在后台代码的事件呢?接着往下:在后台。你定义个方法用来供dropdownlist的selectedindexchanged事件用的。。 Protected Sub ddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Response.Write("<script>alert('你选择了 " & CType(sender, DropDownList).SelectedItem & "';</script>") End Sub这样就可以了。记住要用Protected关键字。恩! 这不是和获取DataGrid 中的一个模板列里的CheckBox的Checked属性类似吗? 页面乱码问题 未将对象引用设置到对象的实例。纠结了我一天了。 .NET网站刚刚做,想做好优化 asp.net mvc中类似Html.ListBox这样的输出html控件拓展方法? asp.net中如何判断一条记录在一张表中 调试了一下ASP局域网写文件,得到了true,纪录到这里,给大家分享一下。 日期格式转化问题! 再问文件保存的问题! 请教怎样把几个.cs文件里的共用代码放到一个文件里,然后在那几个.CS文件里调用? 更换帐号,转分贴,勿回! 测试测试 关于Combox控件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DataGrid</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid Runat="server" id="DataGrid1" ShowFooter="True">
<Columns>
<asp:TemplateColumn>
<FooterTemplate>
<asp:DropDownList Runat="server" ID="myDropDownList" AutoPostBack="True">
<asp:ListItem Value="1">test1</asp:ListItem>
<asp:ListItem Value="2">test2</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
#region 更新数据
public void update1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ string t1=((DropDownList)e.Item.FindControl("yourDropDownListname")).SelectedValue;
conn.Open();
cmd = new SqlCommand(sql,conn);
cmd.ExecuteNonQuery();
conn.Close();
DataGrid1.EditItemIndex = -1;
list();
}
#endregion
System.Web.UI.WebControls.DropDownList myList;
myList=(DropDownList)e.Item.Cells[0].Controls[0].FindControl("myDropDownList");
myList.SelectedIndexChanged +=new EventHandler(myList_SelectedIndexChanged);
}
提示:未将对象引用设置到对象的实例。这是什么问题?
首先你在你的datagrid放了个dropdownlist对吧。现在我就只写dropdownlist的代码就好。恩
<asp:DropDownList ID="ddl" Runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="0" text="男"></asp:ListItem>
<asp:ListItem Value="1" text="女"></asp:ListItem>
</asp:DropDownList>
注意。这里设置了AutoPostBack属性为True.还定义了dropdownlist的SelectedINdexChanged事件。恩。你会说。这个是潜逃在datagrid里的。那怎么找到dropdownlist在后台代码的事件呢?接着往下:在后台。你定义个方法用来供dropdownlist的selectedindexchanged事件用的。。 Protected Sub ddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Write("<script>alert('你选择了 " & CType(sender, DropDownList).SelectedItem & "';</script>")
End Sub这样就可以了。记住要用Protected关键字。恩!
CheckBox的Checked属性类似吗?