1

First, Here is a little fiddle to represent my gridview.

I have a gridview where I've merged the cells on some rows. I then need to be able to get the data from both cells that hasn't been merged and cells that has been merged.

So I have a OnRowCommand that takes commandArgument <%#Eval("col3")%>. This works great for the rows that hasn't had it's cells merged, But for the rows with longcell It wont work. I've also tried <%#Eval("col2")%> with no success.

here is the gridview code (simplified):

<asp:GridView ID="myGridview" runat="server" AutoGenerateColumns="false"
                 OnRowCommand="myGridview_RowCommand">                     
    <Columns>
        <asp:BoundField DataField="col1" HeaderText="col1" />
        <asp:BoundField DataField="col2" HeaderText="col2" />
        <asp:BoundField DataField="col3" HeaderText="col3" />          
        <asp:TemplateField>
            <HeaderTemplate>
                Actions
            </HeaderTemplate>
            <ItemTemplate>
                <asp:ImageButton ID="imbEdit" runat="server" ImageUrl="~/css/images/Edit.png" Width="16" CommandName="wEdit" CommandArgument='<%#Eval("col3")%>' />
            </ItemTemplate>
       </asp:TemplateField>
   </Columns>

here is where I merge the cells:

foreach (int i in rowIndexes)
{
    myGridview.Rows[i].Cells[1].ColumnSpan = 2;
    myGridview.Rows[i].Cells.RemoveAt(2);
}
Johan Hjalmarsson
  • 3,433
  • 4
  • 39
  • 64
  • Where are you changing the ColumnSpan? Which event? – Paul Zahra Jul 22 '14 at 09:43
  • What are the values you are passing in 'col3' or 'col2'? I don't understand. You have an image button which, when you click, you are going to run _RowCommand - surely you would be passing some ID or other? What does 'col3' or 'col2' refer to? – Martin Smellworse Jul 22 '14 at 10:02
  • col3 and col2 are just string of information as a CSV and are practically unique. But if you look at my fiddle. I can get all rows that have 3 cells, but if I try to get the 2cells rows it will allways take the first match (since both their col3-values are null). – Johan Hjalmarsson Jul 22 '14 at 10:55

1 Answers1

0

After some more googleing and searching stack overflow I managed to find this question where Elph made an answer that helped me alot.

I now use CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' to get the index and then I work from there :P

Community
  • 1
  • 1
Johan Hjalmarsson
  • 3,433
  • 4
  • 39
  • 64
  • I always pass the Unique ID for the row and retrieve whatever data I need from that - either from the DataKeyNames collection or from the database. – Martin Smellworse Jul 22 '14 at 12:27