我想在编辑gridview里的数据的时候绑定dropdownlist,而dropdownlist是动态绑定数据库的,请问代码怎么写呀?急...
解决方案 »
- 用模态窗口弹出一个页面可以调父窗体方法,但是用window.showModelessDialog弹出同一个页面,调方法时会报错
- 可不可以写一个程序,上传EXECL时,把十个单个的ECEXL上传生成一个总的EXECL
- javascript怎么访问FreeTextBox控件的Text
- 急,请教各位大哥一个Asp.net的问题!
- aspnet如何获得页面执行时间
- asp.net 2.0 beta是不是不支持中文超链接
- [求助]DataList中LinkButton列问题
- asp.net后台定义公用属性js前台获取有问题
- 怎样打包发布ASP.net程序(包括数据库)
- 再问页面执行顺序
- List对象中存有整型数组,如何找出这些数组中对应位置上的最大值
- 求教
GridView 插入、删除、修改、分页的综合例子
countryID int not null,
countryName nvarchar(30) not null
)insert into countryTable
select 1,N'中国'
union all
select 2,N'美国'
create table cityTable(
cityID int not null,
countryID int not null,
cityName nvarchar(30) not null
)insert into cityTable
select 1,1,N'北京'
union all
select 2,1,N'上海'
union all
select 3,2,N'纽约'
union all
select 4,2,N'华盛顿'<asp:GridView ID="gdv_GridView" runat='server' AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" Width="100%"
enablecaching="false" AllowSortTemp="True" ChangedByPageModel="False"
PageSize="10" OnRowDataBound="gdv_GridView_RowDataBound" >
<Columns>
<asp:BoundField DataField="countryID" HeaderText="id" />
<asp:BoundField DataField="countryName" HeaderText="Name" />
<asp:TemplateField headerText="dropdownlist" >
<ItemTemplate>
<asp:DropDownList ID="ddl_dropdownlist" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>protected void Page_Load(object sender, EventArgs e)
{
gdv_GridView.DataSource = getGdvData();
gdv_GridView.DataBind();
} protected void gdv_GridView_RowDataBound(object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow row = e.Row;
string countryID = row.Cells[0].Text; DropDownList ddl = (DropDownList)row.Cells[1].FindControl("ddl_dropdownlist");
ddl.DataSource = getCity(countryID);
ddl.DataTextField = "cityName";
ddl.DataValueField = "cityID";
ddl.DataBind(); }
} private DataTable getCity(string countryID)
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"");
SqlCommand cmd = new SqlCommand("select cityID,cityName from cityTable where countryID = '" + countryID + "'", conn); try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "city");
dt = ds.Tables["city"];
}
catch
{
}
finally
{
if (conn != null)
conn.Close();
}
return dt;
} private DataTable getGdvData()
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"");
SqlCommand cmd = new SqlCommand("select countryID,countryName from countryTable", conn); try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "cnt");
dt = ds.Tables["cnt"];
}
catch
{
}
finally
{
if (conn != null)
conn.Close();
} return dt;
}