0

This is my GridView:

<asp:GridView ID="GridViewVG" OnRowCommend="GridViewVG_RowCommand" runat="server"/>
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="CheckBoxVG" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="itemName" Text='<% # Eval("itemName") %>' runat="server"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

In c#, I have the method in order to get the items that the user chose:

protected List<string> GridViewVG_RowCommand(object sender, GridViewUpdateEventArgs e)
{
    List<string> l = new List<string>();
    foreach (GridViewRow row in GridViewVG.Rows)
        if (row.RowType == DataControlRowType.DataRow)
        {
            string s = (this.GridViewVG.Rows[e.RowIndex].FindControl("itemName") as Label).Text.Trim();
            CheckBox CheckBoxVG = (this.GridViewVG.Rows[e.RowIndex].FindControl("CheckBoxVG") as CheckBox);
            if (CheckBoxVG.Checked)
                l.Add(s);
        }
    return l;
}

I want to use this list in another method.

This is what I have tried:

protected void selectItemsBT2_Click(object sender, EventArgs e)
{
    List<string> l = GridViewVG_RowCommand(sender, (GridViewUpdateEventArgs)e);
    int[] recipeIdList = w.GetRecipeIdsWithAllItems(l.ToArray());
}

It doesn't work, and I don't know what else can I do to get this list.

Florian
  • 1,019
  • 6
  • 22
KK2007
  • 21
  • 5