我的GridView如下:
<asp:GridView ID="mainGridView" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" OnRowDataBound="mainGridView_RowDataBound">
                      <Columns>
                      <asp:TemplateField HeaderText="ID">
                              <ItemTemplate>
                                  <asp:CheckBox ID="articleID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"articleID") %>'/>
                              </ItemTemplate>
                          <ItemStyle Width="10px" HorizontalAlign="Center" VerticalAlign="Middle" Height="22px" />
                          <HeaderStyle CssClass="mainGrid" />
                          </asp:TemplateField>
   
                          <asp:BoundField DataField="articleTitle" HeaderText="主题" >
                              <HeaderStyle CssClass="mainGrid" />
                          </asp:BoundField>
                          <asp:BoundField DataField="articleSender" HeaderText="发布者" >
                              <ItemStyle Width="60px" />
                              <HeaderStyle CssClass="mainGrid" />
                          </asp:BoundField>
                      </Columns>
                      <RowStyle BackColor="#EFF3FB" />
                      <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                      <HeaderStyle Font-Bold="True" ForeColor="White" CssClass="mainGrid" />
                      <AlternatingRowStyle BackColor="White" />
</asp:GridView>我的CheckBox是个自定义的摸板.而且我做惯了HTML的CheckBox,我好象没有看见CheckBox的Value属性.
问题:
我怎么通过单击一行,钩选中该行的CheckBox ? 
我在处理该行数据时怎么获取该CheckBox的Value ?(比如以前用HTML表单我处理某条新闻时,我会把CheckBox的Value赋值为新闻的ID)

解决方案 »

  1.   

    在 RowDataBound 事件处理程序中写:if(e.Row.RowType==DataControlRowType.DataRow)
    {
      CheckBox chk=(CheckBox)e.Row.FindControl("articleID");
      e.Row.Attributes["onclick"]=chk.ClientID+".checked=true";
    }至于CheckBox控件“处理该行数据时怎么获取该CheckBox的Value”,这种问题应该自己查找入门资料。
      

  2.   

    CheckBox cb = new CheckBox();
                cb = (CheckBox)e.Row.FindControl("CheckBox1");
                if (cb != null)
                {
                    cb.Attributes.Add("onClick", "Chkchanged('" + ((CheckBox)e.Row.Cells[8].Controls[0]).Checked + "')");
                }
    写台写Chkchanged角本。
      

  3.   

    if(e.Row.RowType==DataControlRowType.DataRow)
    {
      CheckBox chk=(CheckBox)e.Row.FindControl("articleID");
      
      e.Row.Attributes["style"] = "cursor:default;";  e.Row.Attributes["onclick"] = "doCheck('" + chk.ClientID + "')";
    }JS:function doCheck(objId)
    {
    var src = event.srcElement;

    if(src.tagName == "INPUT")
    {
    return ;
    }

    var obj = document.all[objId];
    obj.checked = !obj.checked;
    }
    ww.setAttribute("ww") = "新闻ID";
    ww.getAttribute("ww");