I have a Gridview connected to a SQL datasource displaying data, and what I hope to do is retrieve data associated with a selected row through a button and Eval.
Somthing like,
<asp:LinkButton runat=server OnClientClick="RetrieveInfo" Text="Send" />
But I can’t call Eval from code, and I don’t know how to get the DataKey either.
I’ve been scouring the internet, but haven’t found anything nice. Can anyone help me? Would be much appreciated.
EDIT:
<asp:GridView ID="GridView1" Width="100%" runat="server" AutoGenerateColumns="False"
DataKeyNames="ScheduleID" DataSourceID="SqlDataSource1">
<Colums>
<asp:TemplateField HeaderText="Date" SortExpression="Date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Date")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Time" SortExpression="starttime">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("starttime")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat=server OnClientClick="RetrieveInfo" Text="Send" />
</ItemTemplate>
</asp:TemplateField>
</Colums>
</asp:GridView>
It’s skimmed, but that’s basically it.
May this help
Edit your gridview html
<Colums>to</Columns>Gridview Html
Code Behind: