开发者

Gridview grouping - using gridviewheper

Good night,

I used the gridviewhelper to group the rows in a gridview.

GridViewHelper helper = new GridViewHelper(this.Resultados);
  helper.RegisterGroup("EntidadeNome", true, true);
  helper.GroupHeader += new GroupEvent(helper_GroupHeader);
  this.Resultados.DataSource = DT;
  this.Resultados.DataBind();

Each row as two itemtemplate, each one with a checkbox.

     <asp:GridView ID="Resultados" runat="server" AutoGenerateColumns="false" GridLines="None"
                        CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                        ShowHeader="false">
                        <Columns>
                            <asp:BoundField DataField="EntidadeNome" SortExpression="EntidadeNome" />
                            <asp:BoundField DataField="ID" HeaderText="IDLinhascompras" ItemStyle-CssClass="hidden"
                                HeaderStyle-CssClass="hidden" ItemStyle-HorizontalAlign="Center" />
                            <asp:BoundField DataField="Artigo" HeaderText="Artigo" SortExpression="Artigo" ItemStyle-Width="50px"
                                ItemStyle-HorizontalAlign="Center" />
// Some BoundFieds here
                            <asp:TemplateField HeaderText="A" ItemStyle-Width="40px" SortExpression="A">
                                <ItemTemplate>
                                    <asp:CheckBox ID="A" Width="40" runat="server" />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="R" ItemStyle-Width="40px" SortExpression="R">
                                <ItemTemplate>
                                    <asp:CheckBox ID="R" Width="40" runat="server" />
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                        <EmptyDataTemplate>
                        <label>Sem resultados para apresentar</label>
                        </EmptyDataTemplate>
                    </asp:GridView>

I'm having some problems when i search for the rows that have a checkbox checked.

    protected void EnviaArtigos_Click(object sender, EventArgs e)
{

    CheckBox chkA, chkR;

    foreach (GridViewRow dataItem in Resultados.Rows)
    {
        object rows;

        chkA = (CheckBox)dataItem.FindControl("A");
        chkR = (CheckBox)dataItem.FindControl("R");

        if (chkA.Checked)
        {
            try
            {
                Motor.DSO.BDAPL.Execute("UPDATE LINHASCOMPRASSTATUS SET ESTADOTRANS = 'A' WHERE IDLINHASCOMPRAS ='" + dataItem.Cells[1]开发者_运维知识库.Text + "'", out rows,
                    -1);
                this.Resultados.DataSource = null;
                this.Resultados.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
        if (chkR.Checked)
        {
            try
            {
                Motor.DSO.BDAPL.Execute("UPDATE LINHASCOMPRASSTATUS SET ESTADOTRANS = 'R' WHERE IDLINHASCOMPRAS ='" + dataItem.Cells[1].Text + "'", out rows, -1);
                this.Resultados.DataSource = null;
                this.Resultados.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }

I see when debugging, that for some reason the checkbox is checked in the row that have the groupheader, and then, in the row that is effectibly selected, the checkbox is not checked.

So, in few words, how can i bypass the groupheader row and only search the checkboxes in the other rows?

Thank you.

EDIT: The error: Conversion failed when converting from a character string to uniqueidentifier.


Filter out the Header (and optionally the footer) rows by checking the TableSection property of the GridViewRow. The syntax may be slightly off (I mostly do VB), but put something like this after your ForEach declaration...

If (dataitem.TableSection != TableRowSection.TableHeader) {
object rows; 
//Rest of the code goes here...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜