社区
C#
帖子详情
如何在DataList中绑订DropDownList?
洪十二
2004-10-26 11:26:01
如果我从资料库中选择10道选择题,想在每道题后加个答案选择下拉列表.
1.DataList,DropDownList的资料皆来自资料库
2.如何实现绑订?
3.绑订后,我又如何取用户的选择答案?
高手帮忙.
...全文
147
7
打赏
收藏
如何在DataList中绑订DropDownList?
如果我从资料库中选择10道选择题,想在每道题后加个答案选择下拉列表. 1.DataList,DropDownList的资料皆来自资料库 2.如何实现绑订? 3.绑订后,我又如何取用户的选择答案? 高手帮忙.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
洪十二
2004-10-26
打赏
举报
回复
我的代码出现System.NullReferenceException體
DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList1");
行 95: ddl.DataSource = LoadDropList();
Help
redlotoc
2004-10-26
打赏
举报
回复
up
lglesias
2004-10-26
打赏
举报
回复
up
roapzone
2004-10-26
打赏
举报
回复
后台代码参考?
private void Button1_Click(object sender, System.EventArgs e)
{
//保存数据的结构
DataTable oDataTable = new DataTable("OpionInfo");
DataColumnCollection columns = oDataTable.Columns;
columns.Add("dxgcbh",typeof(System.String));
columns.Add("zymcid",typeof(System.String));
//columns.Add("zyryid",typeof(System.String));
columns.Add("opioion",typeof(System.String));
columns.Add("result",typeof(System.String));
columns.Add("userid",typeof(System.String));
columns.Add("username",typeof(System.String));
//columns.Add("userpower",typeof(System.Int16));
DataRow UserInfoRow = Customer.Tables[CustomerData.CUSTOMERS_TABLE].Rows[0];
string vSubCensor =UserInfoRow[CustomerData.LOGOID_FIELD].ToString();
string vSubCensorName = UserInfoRow[CustomerData.NAME_FIELD].ToString();
//循环读出选中的数据
CheckBox oCheckBox = null;
//oDataTable.Rows.Add(
object[] oAarray = new object[6];
string zymc = DropDownList2.SelectedItem.Text.Trim();
string zymcd = DropDownList2.SelectedItem.Value;
string scyj = TextBox1.Text.Trim();
string scjl = DropDownList1.SelectedItem.Value;
foreach(DataListItem oDataListItem in DataList1.Items)
{
oCheckBox = (CheckBox)oDataListItem.FindControl("CBInfo");
if(oCheckBox.Checked)
{
oAarray[0] = ((Label)oDataListItem.FindControl("dxgcbh")).Text;
oAarray[1] = zymcd;
oAarray[2] = scyj;
oAarray[2] = Server.HtmlEncode(oAarray[2].ToString());
oAarray[2] = TransferString(oAarray[2].ToString());
oAarray[3] = scjl;
oAarray[4] = vSubCensor;
oAarray[5] = vSubCensorName;
oDataTable.Rows.Add(oAarray);
}
}
bool SucceOrFalse = (new FSpecialityOpinion()).fSaveSpecialityOpinion(oDataTable);
if(SucceOrFalse)
{
Response.Write("<script>alert('专业意见审查成功')</script>");
Response.Write("<script>window.open('AddSpeOpinion.aspx','MainFrameSetContents');</script>");
}
else
{
Response.Write("<script>alert('分配失败\\n原因\\n可能该项目的状态信息找不到\\n可能数据库发生错误\\n有问题请联系管理员!\\t\\t\\t')</script>");
Button1.Attributes.Add("onclick","return confrimDelete()");
}
}
#endregion
private string TransferString(string Str)
{
Str = Str.Replace("<", "<");
Str = Str.Replace(">", ">");
Str = Str.Replace("'", "''");
Str = Str.Replace(" ", " ");
Str = Str.Replace("\n", "<br>");
Str = Str.Replace("\r\n", "<br>");
Str = Str.Trim();
return Str;
}
public SqlDataReader GetDataSetSource( string oSubProID)
{
SqlConnection sqlcon = new SqlConnection(Configuration.ConnectionString);
SqlCommand sqlcom =new SqlCommand();
sqlcon.Open();
sqlcom.Connection = sqlcon;
sqlcom.CommandText = "select distinct zymcid,zymc from TS_ProjsscInfo"+
" where zgcbh= '"+ oSubProID.Trim()+ "' " ;
SqlDataReader my = null;
try
{
my = sqlcom.ExecuteReader();
/*ListItem OlistItem = new ListItem();
while(my.Read())
{
OlistItem.Value = my.GetSqlValue(0).ToString().Trim();
OlistItem.Text = my.GetSqlValue(1).ToString().Trim();
DropDownList2.Items.Add(OlistItem);
}
*/
}
catch(Exception e)
{
//return null;
throw(e);
}
finally
{
}
return my;
}
roapzone
2004-10-26
打赏
举报
回复
哈哈,参考:
用模版,
用findcontronl
lohoo
2004-10-26
打赏
举报
回复
private void DataListTest_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item)
{
((Label)e.Item.FindControl("lblSub")).Text=(j+1).ToString()+" "+DataBinder.Eval(e.Item.DataItem,"试题内容").ToString(); //显示题目内容
DropDownList ddlist=(DropDownList) e.Item.FindControl("ddListChoice");//找到dropDownList---注,要在DataList的模块中先放入一个dropDownList,它的id就是ddListChoice
ddlist.DataSource =this.createDate();//createDate()函数为取选项函数.每次取一个题目的所有选项.
ddlist.DataBind();
}
}
洪十二
2004-10-26
打赏
举报
回复
Help
Data
List
中
如何响应
DropDown
List
的SelectedIndexChanged事件
Data
List
中
如何响应
DropDown
List
的SelectedIndexChanged事件
data
list
控件
中
使用
DropDown
List
data
list
控件
中
使用
DropDown
List
DropDown
List
SelectedIndexChanged Update Action In
Data
List
详细介绍
DROPDOWN
LIST
在数据网格
中
的更新应用.
在ASP.NET 2.0
中
操作数据之三十三:基于
Data
List
和Repeater使用
DropDown
List
过滤的主/从报表
导言 在前面的使用
DropDown
List
过滤的主/从报表一章里我们...本章我们将学习使用
DropDown
List
包含主记录,而在
Data
List
里显示从记录. 第一步: 增加主/从教程页 首先增加本教程会用到的文件夹(
Data
List
RepeaterFilter
DropDown
List
&
Data
List
;.rar
DropDown
List
&
Data
List
;的demo案例,代码很简洁
C#
110,536
社区成员
642,578
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章