我想在DataList中每一行放一个单选框组,先试了
<asp:datalist id="DataList1" runat="server" Height="41" Width="209">
<ItemTemplate>
<table>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"Serial")%>
, <%# DataBinder.Eval(Container.DataItem,"Subject")%></td>
</tr>
<tr>
<td>
<asp:Label ID="answer" Runat="server">
<%# DataBinder.Eval(Container.DataItem,"Answer")%>
<asp:Label ID="QuesionId" Runat="server">
<%# DataBinder.Eval(Container.DataItem,"QuestionId")%>
</asp:Label>
</asp:Label></td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="sSelAnswer" Runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value='a' Text='<%# DataBinder.Eval(Container.DataItem,"Select1")%>'></asp:ListItem>
<asp:ListItem Value='b' Text='<%# DataBinder.Eval(Container.DataItem,"Select2")%>'></asp:ListItem>
</asp:RadioButtonList></td>
</tr>
</table>
编译通不过
后来我又试了
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Label lbl=(Label)e.Item.FindControl("QuesionId");
RadioButtonList rl=(RadioButtonList)e.Item.FindControl("sSelAnswer");
if(lbl!=null)
{
string sql="SELECT Select1,Select2,Select3 from SelectQuestion WHERE QuestionId="+lbl.Text;
DataSet ds=GetDataSet(sql);
if(rl!=null)
{
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select1"].ToString(),"a"));
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select2"].ToString(),"b"));
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select3"].ToString(),"c"));
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select4"].ToString(),"d"));
}
} }
可这样得到的lbl.Text始终是空,谁知道该怎么做啊
谢谢
<asp:datalist id="DataList1" runat="server" Height="41" Width="209">
<ItemTemplate>
<table>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"Serial")%>
, <%# DataBinder.Eval(Container.DataItem,"Subject")%></td>
</tr>
<tr>
<td>
<asp:Label ID="answer" Runat="server">
<%# DataBinder.Eval(Container.DataItem,"Answer")%>
<asp:Label ID="QuesionId" Runat="server">
<%# DataBinder.Eval(Container.DataItem,"QuestionId")%>
</asp:Label>
</asp:Label></td>
</tr>
<tr>
<td>
<asp:RadioButtonList ID="sSelAnswer" Runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value='a' Text='<%# DataBinder.Eval(Container.DataItem,"Select1")%>'></asp:ListItem>
<asp:ListItem Value='b' Text='<%# DataBinder.Eval(Container.DataItem,"Select2")%>'></asp:ListItem>
</asp:RadioButtonList></td>
</tr>
</table>
编译通不过
后来我又试了
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Label lbl=(Label)e.Item.FindControl("QuesionId");
RadioButtonList rl=(RadioButtonList)e.Item.FindControl("sSelAnswer");
if(lbl!=null)
{
string sql="SELECT Select1,Select2,Select3 from SelectQuestion WHERE QuestionId="+lbl.Text;
DataSet ds=GetDataSet(sql);
if(rl!=null)
{
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select1"].ToString(),"a"));
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select2"].ToString(),"b"));
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select3"].ToString(),"c"));
rl.Items.Add(new ListItem(ds.Tables[0].Rows[0]["Select4"].ToString(),"d"));
}
} }
可这样得到的lbl.Text始终是空,谁知道该怎么做啊
谢谢
解决方案 »
- 怎样使网页中文本框的滚动条一直在底部?
- 数据绑定 超时 怎么办啊!
- 有什么好的办法可以将.net4.0版本改为3.5的版本了?
- asp.net中如何用字节转换为KB呢?
- Microsoft Visual SourceSafe能不能两地之间使用!
- 请问哪里有vss6.0c下载???
- 关于弹出全屏的问题?
- 水晶报表加载图片之后,报表不显示了
- IT出入牛犊!请高手和有经验者进入!! 讨论职场
- 各位大侠:我是用校园网上网的,请问怎么设置才能用QQ啊。谢谢了!
- 求一时间语句:2004年9月27号 星期一 16点40分24秒
- 从类型“DBNull”到类型“String”的强制转换无效。 怎么解决?????
{
//加在这里试验一下
......
}
Label lbl=new Label();
lbl=(Label)e.Item.FindControl("QuestionId");
RadioButtonList rl=(RadioButtonList)e.Item.FindControl("sSelAnswer");
string sql="SELECT Select1,Select2,Select3 from SelectQuestion WHERE QuestionId="+lbl.Text;
lbl.text始终是空值
我以前也写过在DataList中用这样的方法取一个Label的值
并不是空啊
哪位帮帮忙
谢谢
我解决了