2

I have a TemplateField column in a gridview with a button inside of it.

There is NO key value (surely that was not designed by me) , but in the other hand there aren't redundancies when comparing each single column, because they are events, and there is "starting date" and "ending date" of something that could not happen twice at the same time.

I've already figured selecting with these values and all, but I just want the button to pass about five arguments to a given function.

I've tested:

<asp:Button  CommandArgument='<%# Eval("day")%>'  ID="Button2" runat="server" Text="Button" />

And it works properly, the day of the clicked row is passed, and could be retrieved through:

e.CommandArgument.ToString();

in the GridView_RowCommand handler.

How do I pass more than one argument? I've thought about concatenating with a separating character (wouldn't be that bad) but besides not knowing how to do it yet (didn't want to invest in a poor solution) I want a smarter one.

5
  • i was going to ask the same question..!!! Commented Apr 5, 2010 at 12:34
  • 1
    You can concatenate like that: CommandArgument='<%# Eval("day") + ", etc," + Eval("userId") %>' - but yes, I agree that it's a dirty solution. Commented Apr 5, 2010 at 12:53
  • @ MarceloRamires...i am not kidding ... the only different that i am working on vb.. Commented Apr 5, 2010 at 13:02
  • @jjj In fact, I AM working on VB.NET too, but as people in stackoverflow tend to not answer questions when I say I use VB (even when the question doesn't quite involve codebehind programming Commented Apr 5, 2010 at 14:04
  • oh.... realy?!.. it is not a big different..!! Commented Apr 6, 2010 at 6:24

1 Answer 1

2

The easiest way may be to access the GridView row via the button and access the values that way:

void Button2_Click(object o, EventArgs e) {
    Button myButton = (Button)o;
    GridViewRow row = (GridViewRow)muButton.Parent.Parent;

    string value1 = row.Cells[0].Text;
    string value2 = row.Cells[1].Text;
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.