<asp:Label ID="answer1" runat="server" Text="Label" CssClass="option" Width="120">
<div class="div_chn"><asp:Label ID="chinese" runat="server" Text=""></asp:Label></div>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
answer1.Attributes.Add("onclick", "choiceAnswer(this)");//选择传值
}
}function choiceAnswer(obj)
{
$yourChoice=$(obj).text();
$(".div_chn",$(obj).parent().parent()).text($yourChoice);
}Label chinese = e.FindControl("chinese") as Label;
我用jquery让点击answer1时,chinese的值被赋值answer1的值,运行时页面显示正常,但是提交时,没有值,再次调试,监视chinese 的值为空,请问这是为什么?该怎么办
<div class="div_chn"><asp:Label ID="chinese" runat="server" Text=""></asp:Label></div>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
answer1.Attributes.Add("onclick", "choiceAnswer(this)");//选择传值
}
}function choiceAnswer(obj)
{
$yourChoice=$(obj).text();
$(".div_chn",$(obj).parent().parent()).text($yourChoice);
}Label chinese = e.FindControl("chinese") as Label;
我用jquery让点击answer1时,chinese的值被赋值answer1的值,运行时页面显示正常,但是提交时,没有值,再次调试,监视chinese 的值为空,请问这是为什么?该怎么办
if(!ispostback)
{}
了
function choiceAnswer(obj)
{
$yourChoice=$(obj).text();
$(".div_chn",$(obj).parent().parent()).text($yourChoice);
将值赋给HiddenField
}
可以通过ajax 或者hidden控件来实现