DropDownList1和DataGrid1的数据显示问题? 使用自定义绑定,默认的Datagrid是绑定数据表中所有列,通过属性生成器来设置 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在DropDownList 的SelectedIndexChanged事件中,DropDownList的AutoPostBack属性设为trueprivate void DropDownList_SelectedIndexChanged(object sender, System.EventArgs e){得到gcblx我不知道类型,假设为整型int gcblx = Int32.Parse( DropDownList1.SelectedItem.Text );在根据gcblx邦定你DataGrid1string strSql = "select * from youtable where gcblx="+gcblx.ToString;dsCommand.SelectCommand = new SqlCommand( strSql , conn );DataTable dataTable = new DataTable;dsCommand.Fill(dataTable);this.DataGrid1.DataSource = dataTable;this.DataGrid1.DataBind();} 在DropDownList 的SelectedIndexChanged事件中,DropDownList的AutoPostBack属性设为true然后绑定DropDownList的Value为ID建议最好在ProjectInfo中是ID列而不是gcblx列,这样实现起来就更加的方便了。然后在绑定到DataGrid中的时候这样来写SQL语句string strSQL="select * from ProjectInfo, ProjectType where ProjectInfo.gcblx=ProjectType .gcblx";绑定到DataGrid中去就可以了。至于可编辑那就要对DataGrid的一些事件做动作。你先看看能不能把上面的问题解决,解决不掉给我发消息我给你具体大的源码!! 使用DataGrid动态绑定DropDownList http://www.csdn.net/Develop/read_article.asp?id=26590 <asp:TemplateColumn headertext="科目"><ItemTemplate><asp:Label id="lblLabelName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Subject") %>'></asp:Label></ItemTemplate><EditItemTemplate><asp:DropDownList id="ddl" runat="server"></asp:DropDownList></EditItemTemplate></asp:TemplateColumn>private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.EditItem) { DropDownList ddl1=(DropDownList) e.Item.FindControl("ddl"); //定义DataSource ddl1.DataSource=mydatasource; ddl1.DataTextField="gcblx"; ddl1.DataValueField="gcblx"; ddl1.DataBind(); string role=DataBinder.Eval(e.Item.DataItem,"gcblx").ToString(); ddl1.Items.FindByText(role).Selected=true; } } 急,创建控件时出错,基类不是JavaScriptConverter 网址中用用户名问题 迅网壁纸程序可以提供下载 GridView分页以后,自动求和就不对,只求出本页的合计数,怎么解决? Vs2005如何生成一个固定名称的dll? 在ASP.NET中怎么获得confirm()的返回值 高分求教怎样在用户控件中调用它的宿主页面上的其他控件的方法? 请教将字符串生成可以控制的图像 如何取得用form验证的当前用户名及其角色? 在ASP中如何给ACCESS数据库瘦身? 最近碰到了奇怪的问题 我只想显示数据库里满足条件的一条记录到指定的单元格里,请问相关代码是什么??
private void DropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
{
得到gcblx我不知道类型,假设为整型
int gcblx = Int32.Parse( DropDownList1.SelectedItem.Text );
在根据gcblx邦定你DataGrid1
string strSql = "select * from youtable where gcblx="+gcblx.ToString;
dsCommand.SelectCommand = new SqlCommand( strSql , conn );
DataTable dataTable = new DataTable;
dsCommand.Fill(dataTable);
this.DataGrid1.DataSource = dataTable;
this.DataGrid1.DataBind();
}
然后绑定DropDownList的Value为ID建议最好在ProjectInfo中是ID列而不是gcblx列,这样实现起来就更加的方便了。
然后在绑定到DataGrid中的时候这样来写SQL语句
string strSQL="select * from ProjectInfo, ProjectType where ProjectInfo.gcblx=ProjectType .gcblx";
绑定到DataGrid中去就可以了。至于可编辑那就要对DataGrid的一些事件做动作。你先看看能不能把上面的问题解决,解决不掉给我发消息我给你具体大的源码!!
http://www.csdn.net/Develop/read_article.asp?id=26590
<ItemTemplate>
<asp:Label id="lblLabelName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Subject") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddl" runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.EditItem)
{
DropDownList ddl1=(DropDownList) e.Item.FindControl("ddl");
//定义DataSource
ddl1.DataSource=mydatasource; ddl1.DataTextField="gcblx";
ddl1.DataValueField="gcblx";
ddl1.DataBind();
string role=DataBinder.Eval(e.Item.DataItem,"gcblx").ToString();
ddl1.Items.FindByText(role).Selected=true; }
}