我有一个DataGridView控件,里面已经填充好数据,现在我需要通过点击控件中的数据(就是做成超连接的形式),然后赋予到一个文本框,假定名为TextBox1,具体应该怎么做呢?关键是如何将DataGridView中的数据做成可点击的超连接的形式呢?
解决方案 »
- c/s端使用webbrowser控件,然后在页面中使用webbrowser.ExecWB提示没有权限
- ASP.NET论坛帖子用什么显示好,可以用GrvidView吗?
- 各位仁兄,如今有一个笔试题,请大家帮我解决一下,望高手们能帮助小弟,时间紧迫谢谢各位了,就一天半时间!
- 郁闷了两天的Dropdownlist问题,哪位高手指点一下
- 莱鸟的简单问题,用sqldatasource绑定数据,填充到GRIDVIEW中,如何读取某一行某个字段的值?
- 哪有好点的人事管理系统,想参考下界面,谁给推荐个?(要B/S的)
- LABEL循环问题
- Access 怎样连接到ASP。NET呢?
- ASP.NET 2.0 绑定问题
- 关于mvc area路由配置
- treeview鼠标右键,高分!
- 我想问下www.365rili.com这个网站上的日历是不是自己做的控件,怎么实现呢
<a href='<%#Eval("datafield","aa.aspx?text={0}")%'></a>
{
//假定你的第0列为DataGridViewLinkColumn
if (e.ColumnIndex == 0)
{
DataGridViewLinkCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewLinkCell;
textBox1.Text= cell.Value.ToString();
}
}
<a href=' <%#Eval("datafield","aa.aspx?text={0}")%'> </a>
这个超连接,怎么加,什么含义,能不能解释一下啊
就是模版列吧,参考下,对gridview 一样的,找到列的主KEY的方法就可以进行操作了
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %><html>
<script runat="server"> DataTable Store = new DataTable();
DataView StoreView; void Page_Load(Object sender, EventArgs e)
{
if(Session["StoreData"] == null)
{
DataRow dr;
Store = new DataTable(); Store.Columns.Add(new DataColumn("Tax", typeof(String)));
Store.Columns.Add(new DataColumn("Item", typeof(String)));
Store.Columns.Add(new DataColumn("Price", typeof(String))); Session["StoreData"] = Store;
// Create sample data.
for (int i = 1; i <= 4; i++)
{
dr = Store.NewRow(); dr[0] = "0.0%";
dr[1] = "Item " + i.ToString();
dr[2] = (1.23 * (i + 1)).ToString();
Store.Rows.Add(dr);
} }
else
Store = (DataTable)Session["StoreData"]; StoreView = new DataView(Store);
StoreView.Sort="Item"; if(!IsPostBack)
BindGrid();
} void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs e)
{
MyDataGrid.EditItemIndex = e.Item.ItemIndex;
BindGrid();
} void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs e)
{
MyDataGrid.EditItemIndex = -1;
BindGrid();
} void MyDataGrid_Update(Object sender, DataGridCommandEventArgs e)
{
// Get the text box that contains the price to edit.
// For bound columns the edited value is stored in a text box.
// The text box is the first control in the Controls collection.
TextBox priceText = (TextBox)e.Item.Cells[3].Controls[0]; // Get the check box that indicates whether to include tax from the
// TemplateColumn. Notice that in this case, the check box control is
// second control in the Controls collection.
CheckBox taxCheck = (CheckBox)e.Item.Cells[2].Controls[1]; String item = e.Item.Cells[1].Text;
String price = priceText.Text;
DataRow dr; // With a database, use an update command. Since the data source is
// an in-memory DataTable, delete the old row and replace it with a new one. // Remove old entry.
StoreView.RowFilter = "Item='" + item + "'";
if (StoreView.Count > 0)
StoreView.Delete(0);
StoreView.RowFilter = "";
// Add new entry.
dr = Store.NewRow(); if (taxCheck.Checked)
dr[0] = "8.6%";
else
dr[0] = "0.0%";
dr[1] = item;
dr[2] = price;
Store.Rows.Add(dr); MyDataGrid.EditItemIndex = -1;
BindGrid();
} void BindGrid()
{
MyDataGrid.DataSource = StoreView;
MyDataGrid.DataBind();
} </script><body> <form runat="server"> <h3>TemplateColumn Example</h3> <asp:DataGrid id="MyDataGrid" runat="server"
BorderColor="black"
CellPadding="2"
OnEditCommand="MyDataGrid_Edit"
OnCancelCommand="MyDataGrid_Cancel"
OnUpdateCommand="MyDataGrid_Update"
ShowFooter="True"
AutoGenerateColumns="false"> <Columns> <asp:EditCommandColumn
EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
ItemStyle-Wrap="false"
HeaderText="Edit Controls"/> <asp:BoundColumn HeaderText="Description"
ReadOnly="true"
DataField="Item"/> <asp:TemplateColumn> <HeaderTemplate>
<b> Tax </b>
</HeaderTemplate> <ItemTemplate>
<asp:Label
Text='<%# DataBinder.Eval(Container.DataItem, "Tax") %>'
runat="server"/>
</ItemTemplate> <EditItemTemplate> <asp:CheckBox
Text="Taxable"
runat="server"/> </EditItemTemplate> <FooterTemplate>
<asp:HyperLink id="HyperLink1"
Text="Microsoft"
NavigateUrl="http://www.microsoft.com"
runat="server"/>
</FooterTemplate> </asp:TemplateColumn> <asp:BoundColumn HeaderText="Price"
DataField="Price"/> </Columns> </asp:DataGrid> </form></body>
</html>
。
跳转到aa.aspx页面,传参数为text,值为datafield(即你的字段)
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javascript:getCellValue('<%#Eval("Account") %>')" id='<%# Eval("Account","AccountHref{0}") %>'><%# Eval("Account") %></a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<script language="javascript" type="text/javascript">
function getCellValue(accId)
{
alert(document.getElementById("AccountHref"+accId).innerHTML);
document.getElementById('<%= TextBox2.ClientID %>').value=document.getElementById("AccountHref"+accId).innerHTML;
}
</script>
当点击链接时,使用javascript把链接的值放入TextBox2.
请问下,你们都说text={0},这个表示传参,那么这个{0},难道是这个字段的值?
<%# Eval("Account","AccountHref{0}") %>'>
Eval是取值的明明吗?AccountHref{0}又是什么含义?
-----------
这个是构造javascript代码,绑定Account做为getCellValue的参数id='<%# Eval("Account","AccountHref{0}") %>'>
-----------
这个是设置<a>标记的ID,javascript是通过id来找到某个<a>标记并获得它的innerHTML值的。
ID必须是惟一的,这里我假定Account是一个主键列或者惟一列,假如Account的值为god_xp,那么<a>的ID就是"AccountHrefgod_xp"
之所以加个AccountHref前缀,是为了防止页面中还有其他的同ID的HTML标记,没有其他意思,你可以使用任何的前缀,即使不使用前缀也行(前提是要保证ID是唯一的)。<%# Eval("Account") %>
---------------
这个是设置<a>标记在客户端显示的内容,也就是javascript中要获取的值.
如果你有装MSDN,可以参考
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_aspnetcon/html/14cdd57d-0f82-4667-b503-73e1a96f136a.htm
也可以在baidu或google中搜索"ASP.NET数据绑定表达式"
也可以用javascript实现,加个超链接,链接中写个onclick事件,出发事件,将值付给textbox就可以了
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263
08年英语专业四级答案出售,绝对包过!!QQ:75934263[/color]