Reputation: 315
I have 2 questions about Gridview:
1.I have enabled the selecting a row property in gridview, but I don't know how can I access the values of the row which has been selected?
2.as you see in my code I have a name parameter in my datasource and I want to value it with "session[search]"(for example) but I don't know how should I do it?
That is piece of my code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [information] WHERE (CONTAINS([nam], @nam))" >
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="nam"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Upvotes: 3
Views: 10269
Reputation: 2570
Question 1: Ans
Set the DataKeyNames of the grid view of the column name (say the ID from the DB which is in the Result set).
Now in the SelectedIndexChanged event handler writ the following code
int selectedIndex = GridView1.SelectedIndex;
string informationID= (GridView1.DataKeys[selectedIndex]["InformationID"]).ToString();
gridview1.Rows[selectedIndex].cells("name").Text
Question 2:Ans
in datasource use sessionparameter for session
<SelectParameters>
<asp:SessionParameter Name="nam" SessionField="select" Type="String" />
</SelectParameters>
Upvotes: 3
Reputation: 98750
I have enabled the selecting a row property in gridview, but I don't know how can I access the values of the row which has been selected?
You can use GridView.SelectedRow
property.
Gets a reference to a GridViewRow object that represents the selected row in the control.
Like Gridview1.SelectedRow.Cells[0]
, Gridview1.SelectedRow.Cells[1]
etc..
I don't understand your second question at all..
Upvotes: 1