DataGrid模版列超级链接列传递参数问题总结(多个参数传递)

1、存在小错误,总体方法是对的,使用java脚本

NavigateUrl="javascript:var win=window.open('<%# "ksmd.aspx?kcbh="+DataBinder.Eval(Container,"DataItem.课程编号")+"&ksrq="+DataBinder.Eval(Container,"DataItem.考试日期")%>','','height=250,width=700,top=250,left=150,toolbar=no,menubar=no,crollbars=no,resizable=no,location=no,status=no')"
2、

The DataGrid's HyperLinkColumn column is great to have a column with an hyperlink that points to an Url with a parameter whose value is taken from the data source, but what if you need to build the target Url with more than one parameter taken from the data source? In this case you can use a template column as follows:

<TemplateColumn>
    <ItemTemplate>
       <asp:HyperLink Runat="server" NavigateUrl='<%# "Details.aspx?EmployeeID=" & Container.DataItem("ID")&"&EmployeeName=" & Container.DataItem("FirstName")%>'/>
    </ItemTemplate>
</TemplateColumn>

Instead of doing the string concatenation yourself you can use the BuildUrlWithQueryString function, which must be declared with Public/Protected visibility in the code-behind, as follows:

<TemplateColumn>
    <ItemTemplate>
      <asp:HyperLink Runat="server" NavigateUrl='<%# _
         BuildUrlWithQueryString("Details.aspx", "EmployeeID", Container.DataItem("ID"),"EmployeeName", Container.DataItem("FirstName")) %>' />
   </ItemTemplate>
</TemplateColumn>

http://java.mblogger.cn/brian_jin/posts/2792.aspx

<asp:TemplateColumn HeaderText="购买">
<ItemTemplate>
<asp:HyperLink id=HyperLink1 runat="server"
 Text='<%# DataBinder.Eval(Container, "DataItem.dinggou")%>'
 NavigateUrl='<%# "../gouwu/gouwu_ls.aspx?commoditytype=" &
  DataBinder.Eval(Container, "DataItem.commoditytype")
  & "&commodityname=" & DataBinder.Eval(Container, "DataItem.commodityname")%>' />
</ItemTemplate>
</asp:TemplateColumn>

3、

<Asp:TemplateColumn HeaderText=="栏目名称">
 <itemTemplate>
<asp:HyperLink Text='<%# DataBinder.Eval(Container, "DataItem.ica_name") %>' NavigateUrl='<%# "newsdetail.aspx?id="+DataBinder.Eval(Container, "DataItem.ica_id")+"&name="+DataBinder.Eval(Container, "DataItem.ica_name") %>' runat="server"/>
 </itemTemplate>
</Asp:TemplateColumn>

4、固定的文字显示用href
<asp:TemplateColumn HeaderText="标题">
<HeaderStyle Width="14%"></HeaderStyle>
          <ItemTemplate>
    <a href=content.aspx?postid=(<%#DataBinder.Eval(Container.DataItem,"postid")%>)'>显示</a>
          </ItemTemplate>
</asp:TemplateColumn>

5、DataGrid超级链接列(HyperLinkColum)中如何绑定一个以上字段,传递多个参数?

a.
<asp:HyperLinkColumn DataTextField="ffff" HeaderText="fff" NavigateUrl="a.aspx?x=<%# DataBinder.Eval(Container.DataItem, "字段名1")%>&s=<%# DataBinder.Eval(Container.DataItem, "字段名2")%>"></asp:HyperLinkColumn

b.
Page.Response.Redirect("repair_fitting_edit.aspx?repair_name="+MyDataGrid.Items[e.Item.ItemIndex].Cells[0].Text+"&fitting_get_day="+MyDataGrid.Items[e.Item.ItemIndex].Cells[1].Text+"&fitting_no="+MyDataGrid.Items[e.Item.ItemIndex].Cells[2].Text);

c.

先将datagrid转换到模板列,然后在模板列中hyperlink的“属性”—> “绑定”-> text 内容里填写以下内容:

DataBinder.Eval(Container.DataItem, "字段名1") + DataBinder.Eval(Container.DataItem, "字段名2")

 

6、此方法未经验证:

<%
string Window;

Window = Request.QueryString["Window"];
%>

<frame src="left_tree_list_map.aspx?dm_tree=101&Window=<%=Window%>" name="leftFrame" scrolling="auto">

 

7、以上均为在页面中直接编写HTML实现,此种方法直接编写.cs文件

string connstr = @"Integrated Security=SSPI;User ID=sa;Initial Catalog=Northwind;Data Source=MyServer\NetSDK";

SqlConnection cnn=new SqlConnection(connstr);

SqlDataAdapter da=new SqlDataAdapter("select * from employees", cnn);

DataSet ds=new DataSet();

da.Fill(ds, "employees");

ITemplate temp= Page.LoadTemplate("webusercontrol1.ascx");

TemplateColumn tc=new TemplateColumn();

tc.HeaderText = "Last Name";

tc.ItemTemplate = temp;

DataGrid1.Columns.Add(tc);

DataGrid1.DataSource = ds;

DataGrid1.DataMember = "employees";

DataGrid1.DataBind();

你可能感兴趣的:(datagrid)