Wednesday 15 June 2011

c# - ASP.net checkbox state is not being read correctly -


How can I remove select a gridview with the display of the data, an additional checkbox column I items. My gridview is kept in this way:

  & lt; Div class = "my_gv" & gt; & Lt; Asp: UpdatePanel id = "update_panel" updatemod = "conditional" runat = "server" & gt; & Lt; ContentTemplate & gt; & Lt; Asp: GridView ID = "my_gv" runat = "server" AutoGenerateColumns = "false" gridlines = "no" width = "100%" AllowSorting = "right" CssClass = "Table Table bordered X-intensive cameraDetails" OnRowDataBound = "my_gv_RowDataBound "& Gt; & Lt; Columns & gt; & Lt; ASP: TemplateField & gt; & Lt; HeaderTemplate & gt; & Lt; Asp: checkbox id = "select ALL_ChckBx" run = "server" onclick = "Select All checkbox (this);" Meta: Resources = "Select All_ChckBxResource1" /> & Lt; / HeaderTemplate & gt; & Lt; ItemTemplate & gt; & Lt; ASP: Czech box id = "row_select_checkbox" runat = "server" meta: resourceKey = "row_select_checkbox_resource" / & gt; & Lt; / ItemTemplate & gt; & Lt; Header style CssClass = "CAMheader" /> & Lt; Item style CssClass = "item entry chkBx" width = "25px" /> & Lt; / ASP: TemplateField & gt; // erosion   

is to handle the removal of my argument following:

  {foreach (GridViewRow line my_gv.Rows) if (row.RowType ! = DataControlRowType.DataRow) {Continue; } Var chkBox = row.FindControl ("row_select_checkbox"); If (chkBox.Checked) {// Cutting}   

It seems to make sense to me, but. The checked method is always returning incorrect, regardless of the actual state of the checkbox . I'm able to access from Gridview to other (text) columns, all right.

So, what am I doing wrong? How can I get the checkbox state? Thanks for any help

I recommend creating a BindGrid method to obtain a list of data Works on the grid, and then actually calling the databand, the method can optionally accept a list as the way all the methods are bound with Gridview. Then you can do the following in your Prisht_lod:

  if (! Page.IsPostBack) {BindGrid (); }   

This gives you the flexibility to call compulsive logic if you need to update the grid (i.e. grid paging or sorting).

No comments:

Post a Comment