kalls
kalls

Reputation: 2865

GridView and Textboxes

I have a gridview and I am able to render textboxes, enter value and save it to the database.

  <asp:TemplateField>
     <ItemTemplate>
         <asp:TextBox ID="txtSomething" runat="server" Text='<%# Bind("SOME_COL") %>'></asp:TextBox>
      </ItemTemplate>
      <ItemStyle Width="10%" />
   </asp:TemplateField>
    <asp:TemplateField HeaderStyle-ForeColor="white" 
                       HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="5%">
       <ItemTemplate>
            <asp:LinkButton Id="btnSomething" runat="server" 
                            CommandArgument='<%# Eval("SOME_ID") %>' 
                            CommandName="WaitPeriodSave" CausesValidation="false"
                 >Save</asp:LinkButton>

The command argument is SOME_ID and it might contain value 4, but it might be 2nd row on the gridview.

Can I pass more than one value in command argument? If yes, How? Also, is there a way to determine the selected row number In the above scenario it is 2 which is probably zero based so it should be 1.

Upvotes: 0

Views: 181

Answers (1)

Icarus
Icarus

Reputation: 63970

CommadArgument is of type string; therefore, if you want to pass more than one argument in the CommandArgument property, you have to come up with some sort of convention to do it, for example, concatenating the arguments and separating them by commas and then split them on the code behind. For example:

CommandArgument='<%# string.Format("{0},{1}",Eval("SOME_ID"),Eval("OTHER_PROPERTY")) %>' 

Upvotes: 3

Related Questions