Hi everyone. I'm new to asp.net and I'm having problem extracting the content of a cell when a user click on a particular row in my gridview.
Have try all solutions I have found on the net, but I still can't figure it out.
I'm using AccessDataSource. And it select Report Name and Site Location from my table report. Below is my AccessDataSource code:
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/VirtualLibrary.mdb"
SelectCommand="SELECT [reportName] AS [Report Name], [siteLocation] AS [Site Location] FROM [tblReport]" FilterExpression="[Report Name] like '%{0}%' OR [Site Location] Like '%{1}%'">
<FilterParameters>
<asp:ControlParameter Name="reportName" ControlID="txtSearch" PropertyName="Text" />
<asp:ControlParameter Name="siteLocation" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:AccessDataSource>
My Gridview display 2 columns, Report Name and Site Location. I have also a hidden Select button:
<asp:GridView ID="myGridView" DataSourceID="AccessDataSource2" runat="server" DataKeyNames = "Report Name"
AutoGenerateColumns = "False"
AllowPaging = "True"
AllowSorting = "True"
CellPadding = "4"
ForeColor = "#333333"
GridLines="None" Width="433px"
>
<Columns>
<asp:ButtonField CommandName= "Select" Visible= "False" />
<asp:TemplateField HeaderText="Report Name" SortExpression="reportName">
<ItemStyle Width="200px" HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblReportName" Text='<%# HighlightText(Eval("Report Name")) %>'
runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Site Location" SortExpression="siteLocation">
<ItemStyle Width="120px" HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblSiteLocation" Text='<%# HighlightText(Eval("Site Location")) %>'
runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#333399" ForeColor="White" Font-Bold="True" />
<RowStyle BackColor="#CCCCCC" />
<AlternatingRowStyle BackColor="White" />
<PagerStyle BackColor="#333399" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="lightcyan" />
</asp:GridView>
I have a function in my aspx.vb file which highlight rows when mouse is over:
Protected Overrides Sub Render(ByVal writer As _
System.Web.UI.HtmlTextWriter)
For Each row As GridViewRow In myGridView.Rows
If row.RowType = DataControlRowType.DataRow Then
row.Attributes("onmouseover") = _
"this.originalstyle=this.style.backgroundColor; this.style.cursor='hand'; this.style.backgroundColor='LightCyan'"
row.Attributes("onmouseout") = _
"this.style.backgroundColor=this.originalstyle"
row.Attributes("onclick") = ClientScript.GetPostBackEventReference(myGridView, "Select$" & row.DataItemIndex, True)
row.ToolTip = "Click click to select row "
End If
Next
MyBase.Render(writer)
End Sub
And some function which will allow me to search for a report and then it will highlight everywhere in my gridview where my search text occur. Have got this on the net:cool:
But problem occur when i want to copy the content of a cell in the Report Name column when a user click on a row in my gridview. Have got a lot of solutions on the net, but none seems to work for me.
Is there something I have write wrong, or something that I need to add. Plz help me...