如何获取gridView 中的dorpDownList 名称(ID)??
dropDownList 是gridView中的一模版列!!
我想在gridview赋完datasource后,
能让dropdownlist 实现
dropdownlist.DataSource=数据源
dropdownlist.DataValueField=数据源
dropdownlist.DataTextField=数据源
高手指点!!!
dropDownList 是gridView中的一模版列!!
我想在gridview赋完datasource后,
能让dropdownlist 实现
dropdownlist.DataSource=数据源
dropdownlist.DataValueField=数据源
dropdownlist.DataTextField=数据源
高手指点!!!
解决方案 »
- 请问用户控件中AjaxPro的使用
- 求过滤危险字符函数,万分感谢!!!
- 为什么“隐藏已知文件类型的扩展名”前面的勾去掉了,刷新目录后又勾上了?
- 奇怪,为什么我用我加个TextBox1和Button1,提交具体那一页,databinding事件没执行?
- 菜鸟问题
- 这个网站问题是程序问题还是服务器空间问题,请一定看看啊,急喔
- 为什么直接打开aspx页面出错,而“在新窗口中打开”正常???
- 哪里有广东地区天气预报的Web服务?
- 如何将客户端按钮的点击事件邦定到服务端按钮的点击事件上
- 在ASP.NET里调用OUTLOOK的代码怎么写啊??
- 从字符串向 datetime 转换时失败的问题
- 给动态生成表格添加图片?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
dorpDownList 名称= (dorpDownList)GridView1.FindControl("名称") ;
}
foreach(Control c in GridView1.Rows[rowindex].Cells[colindex].Controls)
{
if (c is DropDownList)
{
DropDownList ddl = c as DropDownList;
//ddl.ID
}
}
DropDownList dr= (DropDownList )GridView1.Rows[i].FindControl("DropDownList的名字");
{
if (e.Row.RowIndex >= 0)
{
//填充編號
Label lblNo = (Label)e.Row.FindControl("lblNo");
if (i < 10)
{
lblNo.Text = "0" + i.ToString() + ".";
}
else
{
lblNo.Text = i.ToString() + ".";
}
i++; if (e.Row.RowIndex >= 1)
{
e.Row.Cells[2].Text = GridView1.Rows[e.Row.RowIndex - 1].Cells[2].Text; } Label Label1 = (Label)e.Row.FindControl("Label1"); //繳款項目不能為空.如果為空則是 新增的.顯示 新增控件
if (String.IsNullOrEmpty(Label1.Text.Trim()))
{
//這裏是對樓主問題的答復。。
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlProject"); //交款項目顯示
DataSet ds = getddlProject();
ddl.DataSource = ds;
ddl.DataTextField = "codename";
ddl.DataValueField = "codeno";
ddl.DataBind(); ddl.Visible = true;
Label1.Visible = false; TextBox txtCount = (TextBox)e.Row.FindControl("txtCount"); //應繳費用顯示
txtCount.Visible = true;
Label Label2 = (Label)e.Row.FindControl("Label2");
Label2.Visible = false; Button btn_Save = (Button)e.Row.FindControl("btn_Save"); //顯示保存按鈕
btn_Save.Visible = true; Label lblExplain = (Label)e.Row.FindControl("lblExplain"); //說明
lblExplain.Visible = false;
TextBox txtExplain = (TextBox)e.Row.FindControl("txtExplain");
txtExplain.Visible = true;
} }
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "lineHighLight(this)";
if ((e.Row.RowIndex % 2) == 1)
{
e.Row.Attributes["onmouseout"] = "lineHighLightBack1(this)";
}
else
{
e.Row.Attributes["onmouseout"] = "lineHighLightBack(this)";
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
//DateTime time_now = TimeNow.AddDays(-TimeNow.Day);
//Response.Write(time_now.ToString()); GridView1.DataSource = getDataTable();
GridView1.DataBind();
} public DataTable getDataTable()
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("ID", typeof(int));
dt.Columns.Add(dc);
DataColumn dc2 = new DataColumn("Name", typeof(string));
dt.Columns.Add(dc2); DataRow dr = dt.NewRow();
dr["ID"] = 1;
dr["Name"] = "aaaaa";
dt.Rows.Add(dr); DataRow dr2 = dt.NewRow();
dr2["ID"] = 2;
dr2["Name"] = "bbb";
dt.Rows.Add(dr2); return dt;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//假设你想得到不同的ddl里的值,这个就需要你在得到数据的方法里传入参数。
DropDownList ddl = ((DropDownList)e.Row.Cells[2].FindControl("DropDownList1"));
ddl.DataSource = getDataTable();
ddl.DataTextField = "Name";
ddl.DataValueField = "ID";
ddl.DataBind();
}
}
页面文件内容:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>