在.net中,Datalist绑定的数据如何进行传参?
我用Datalist进行数据的绑定,我想把里面的数据用超连接的形式进行参数传递,传到另外一个页面去,请问该怎么传?请高手指点!...
我用Datalist进行数据的绑定,我想把里面的数据用超连接的形式进行参数传递,传到另外一个页面去,请问该怎么传?请高手指点!
展开
1个回答
2013-07-22
展开全部
在datalist中数据库绑定 ,使得通过标题来访问文章.弹出窗口
ps :你弹出的窗口可能被你的浏览器阻止,注意观察网页的顶端哦!
前台绑定:
<ItemTemplate >
<img src="image/ddd.gif" width="10" height="10" /> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="select" ForeColor="#0e3198" Font-Underline =False CssClass="css/bcs.css" Font-Size="12px" ><%# DataBinder.Eval(Container.DataItem,"newsTitle") %></asp:LinkButton>
</ItemTemplate>
后台绑定:
protected void Page_Load(object sender, EventArgs e)
{
DataList1.DataSource = bc.GetDataSet("SELECT TOP 8 * FROM news ", "news");
DataList1.DataKeyField = "newsID";
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string strLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
DataSet ds = bc.GetDataSet("select * from news where newsID='" + id + "'", "news");
DataRow[] row = ds.Tables[0].Select();
foreach (DataRow rs in row)
{
strLink = rs["Url"].ToString();
}
Response.Write("<script language=javascript>window.open('" + strLink + "')</script>");
}
或者另外的要求
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string strLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
Response.Write("<script language=javascript>window.open('showNews.aspx?id=" + id + "','')</script>");
}
在showNews.aspx上
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = bc.GetDataSet("select * from news", "news");
DataRow[] row = ds.Tables[0].Select("newsID="+Request.QueryString["id"]);
foreach (DataRow rs in row)
{
this.Page.Title = rs["newsTitle"].ToString();
Label1.Text = rs["newsTitle"].ToString();
TextBox1.Text =" "+ rs["content"].ToString();
}
}
ps :你弹出的窗口可能被你的浏览器阻止,注意观察网页的顶端哦!
前台绑定:
<ItemTemplate >
<img src="image/ddd.gif" width="10" height="10" /> <asp:LinkButton ID="LinkButton1" runat="server" CommandName="select" ForeColor="#0e3198" Font-Underline =False CssClass="css/bcs.css" Font-Size="12px" ><%# DataBinder.Eval(Container.DataItem,"newsTitle") %></asp:LinkButton>
</ItemTemplate>
后台绑定:
protected void Page_Load(object sender, EventArgs e)
{
DataList1.DataSource = bc.GetDataSet("SELECT TOP 8 * FROM news ", "news");
DataList1.DataKeyField = "newsID";
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string strLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
DataSet ds = bc.GetDataSet("select * from news where newsID='" + id + "'", "news");
DataRow[] row = ds.Tables[0].Select();
foreach (DataRow rs in row)
{
strLink = rs["Url"].ToString();
}
Response.Write("<script language=javascript>window.open('" + strLink + "')</script>");
}
或者另外的要求
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string strLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
Response.Write("<script language=javascript>window.open('showNews.aspx?id=" + id + "','')</script>");
}
在showNews.aspx上
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = bc.GetDataSet("select * from news", "news");
DataRow[] row = ds.Tables[0].Select("newsID="+Request.QueryString["id"]);
foreach (DataRow rs in row)
{
this.Page.Title = rs["newsTitle"].ToString();
Label1.Text = rs["newsTitle"].ToString();
TextBox1.Text =" "+ rs["content"].ToString();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询