当前位置: 代码迷 >> ASP.NET >> 用js如何获得选中行的值,主意界面上没有checkBox
  详细解决方案

用js如何获得选中行的值,主意界面上没有checkBox

热度:2958   发布时间:2013-02-25 00:00:00.0
用js怎么获得选中行的值,主意界面上没有checkBox
<asp:GridView ID="GridViewShow" runat="server" 
  AutoGenerateColumns="False" Width="100%" AutoGenerateSelectButton="True" 
  onrowdatabound="GridViewShow_RowDataBound" 
  DataKeyNames="SMSID" onrowcreated="GridViewShow_RowCreated">
  <Columns>
  <asp:TemplateField HeaderText="备注">
  <ItemTemplate>
  <img ID="imgSMSid" alt="" src="" onclick="showFloat();" runat="server" /> 
  <input type="hidden" name="hddReamrk" id="hfRemark" value='<%#Eval("Remark") %>' runat="server" />
  </ItemTemplate>
  </asp:TemplateField>
  </Columns>
  </asp:GridView>

------解决方案--------------------------------------------------------
还有你上面的事件中可以将当前点击的对象直接传进来。

C# code
onclick="getvalue(this);"
------解决方案--------------------------------------------------------
这个是我测试的。。也传上来给你看看是不是你要的效果。。

C# code
<body><table><tr><td><img ID="imgSMSid" alt="" src="" onclick="getvalue(this);" runat="server" />  <input type="hidden" name="hddReamrk" id="hfRemark" value='3' runat="server" /></td></tr></table></body></html><script type="text/jscript">function getvalue(o){    var img = o;    var SMS = img.parentNode.childNodes.item(2).value;    alert(SMS);    }</script>
------解决方案--------------------------------------------------------
前台加
<asp:HiddenField ID="Hi_Code" runat="server" />
后台
if (e.Row.RowType == DataControlRowType.DataRow)
{
string code = ((Label)e.Row.FindControl("Label1")).Text; // 需要选中的控件值
e.Row.Attributes.Add("onclick", string.Format("selectx(this);document.getElementById('{0}').value='{1}';", Hi_Code.ClientID, code));
//把每行 加事件.
}
取值的时候 直接 Hi_Code.Value .
  相关解决方案