将单元格内容从gridview复制到文本框 [英] copy cell content from a gridview to a textbox
问题描述
大家好.我是asp.net的新手,当用户单击我的gridview中的特定行时,提取单元格的内容时遇到问题.
尝试尝试我在网上找到的所有解决方案,但仍然无法解决.
我正在使用AccessDataSource.然后从我的表格报告中选择报告名称"和站点位置".以下是我的AccessDataSource代码:
< asp:AccessDataSource ID =" runat =" 服务器" DataFile 〜/App_Data/VirtualLibrary.mdb"
SelectCommand =" SELECT [reportName] AS [报告名称],[siteLocation] AS [站点位置]来自[tblReport]" FilterExpression [报告名称],例如'%{0}%'或[网站位置]如'%{1}%'" < FilterParameters >
< asp:ControlParameter 名称 =" ControlID txtSearch " PropertyName 文本" / < asp:ControlParameter 名称 =" ControlID txtSearch " PropertyName 文本" / < /FilterParameters >
< /asp:AccessDataSource >
我的Gridview显示2列,即报告名称和站点位置.我还有一个隐藏的选择"按钮:
< asp:GridView ID =" DataSourceID =" AccessDataSource2" runat 服务器" DataKeyNames ="
AutoGenerateColumns = " 错误"
AllowPaging ="
AllowSorting = " 真实"
CellPadding ="
ForeColor =" #333333"
GridLines =" 无" 宽度 =" 433px"
>
< 列 >
< asp:ButtonField CommandName =" 可见 错误" / < asp:TemplateField HeaderText =" SortExpression reportName" < ItemStyle =" 200px" HorizontalAlign 左" / >
< ItemTemplate >
< asp:Label ID =" 文本 <%#HighlightText(Eval(" ))%> '
runat 服务器" / >
< /ItemTemplate >
< /asp:TemplateField >
< asp:TemplateField HeaderText =" SortExpression siteLocation" < ItemStyle =" 120px" HorizontalAlign 左" / >
< ItemTemplate >
< asp:Label ID =" 文本 <%#HighlightText(Eval(" ))%> '
=" 服务器" / >
< /ItemTemplate >
< /asp:TemplateField >
< /列 >
< HeaderStyle BackColor #333399 " ForeColor 白色" 字体粗体 =" >
< RowStyle BackColor =" #CCCCCC" / >
< AlternatingRowStyle =" 白色" / < PagerStyle =" #333399" ForeColor =" =" 中心" / < SelectedRowStyle =" lightcyan" / < /asp:GridView >
我的aspx.vb文件中有一个函数,该函数会在鼠标悬停时突出显示行:
受保护的 替代 Sub 渲染( ByVal 编写器 As _
System.Web.UI.HtmlTextWriter)
对于 每个行 As GridViewRow 在 myGridView.Rows中
如果 row.RowType = DataControlRowType.DataRow 然后
row.Attributes(" )= _
"
row.Attributes(" )= _
"
' 将最后一个参数设置为True
' 注册以进行事件验证.
row.Attributes(" )= ClientScript.GetPostBackEventReference(myGridView, 选择$"&row.DataItemIndex," "行
结束 如果
下一步
MyBase .Render(编写器)
结束 子
还有一些功能可以让我搜索报告,然后突出显示在我的网格视图中出现搜索文本的所有位置.网上有这个:cool:
但是,当用户单击网格视图中的一行时,当我想在报告名称"列中复制单元格的内容时,就会出现问题.网上有很多解决方案,但似乎没有一个对我有用.
是否有我写错的东西或需要添加的东西.请帮我...
"& row.DataItemIndex," "行 结束 如果 下一步 MyBase .Render(编写器) 结束 子
还有一些功能可以让我搜索报告,然后突出显示在我的网格视图中出现搜索文本的所有位置.网上有这个:cool:
但是,当用户单击网格视图中的一行时,当我想在报告名称"列中复制单元格的内容时,就会出现问题.网上有很多解决方案,但似乎没有一个对我有用.
是否有我写错的东西或需要添加的东西.请帮我...
< pre></pre>< script type ="text/javascript" mode ="hold"/>
(document).ready(function(){< br/> < br/>
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"
' Set the last parameter to True
' to register for event validation.
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...
" & 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...
<pre></pre><script type="text/javascript" mode="hold" />
(document).ready(function () {<br /> <br />
这篇关于将单元格内容从gridview复制到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!