0

I have a grid in which all columns are boundfield and one template field, which is a link button.

On clicking the link button, I need to display the grid column values in to a panel which has textboxes, checkbox etc. I am using a Row_Command event for this.

eg: textboxname.text= grid's name column value

I would like not to use rows(0).cells(0) command. Instead of specifying the row or cell number can I do this in Row_Command event. Please help!

Satinder singh
  • 10,100
  • 16
  • 60
  • 102
asn
  • 11
  • 1
  • 1
  • `textboxname.text= grid's name column value` what you want exactly ? selected row cell value or select row column name (Header) ? – Satinder singh May 18 '13 at 11:01

1 Answers1

0

I think you should just link a DetailsView to the GridView's selected index. This would accomplish exactly what you're trying to do, without all the extra work.

Just handle the SelectedIndexChanged event of the GridView, and point your DetailsView's datasource at the ID of the row you've selected. Or, if you're using an SqlDataSource for the DetailsView, you can just use a ControlParameter pointing to the GridView.

General example: You have a GridView, a DetailsView, and the DetailsView is populated by a SqlDataSource. Then you just set up your SqlDataSource to have a ControlParameter that is linked to the selectedValue of the Gridview:

<asp:GridView ID="yourGridView" runat="server" >
...
</asp:GridView>

<asp:DetailsView ID="yourDetailsview" runat="server" DataSourceID="detailsViewDataSource">
...
</asp:DetailsView>

<asp:SqlDataSource ID="detailsViewDataSource" runat="server" ConnectionString="Your connection string"
    SelectCommand="SELECT * FROM yourTable WHERE ID = @ID"
    <SelectParameters>
        <asp:ControlParameter Name="ID" ControlId="yourGridView" PropertyName="SelectedValue"/>
    </SelectParameters>
</asp:SqlDataSource>

If you are not using an SqlDataSource, you need to handle the GridView's SelectedIndexChanged event, and then bind the DetailsView (using the new SelectedValue of your GridView) to the record you need using whatever databinding process you'd like.

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
  • @asn Glad I could help. FYI, if this answer solved your problem, you can [accept it using the checkmark](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235). – Josh Darnell May 19 '13 at 05:30