没有提示任何错误,网页能够出现,,但是点击Datalist里的链接后却没有反应
前台Datalist的代码:
<asp:DataList ID="DataList1" runat="server" Height="1px"
Width="1px" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<table border="0" cellspacing="0" class="txt" style="width: 185px; height: 20px">
<tr>
<td colspan="3" style="height: 20px" align="center">
<asp:Image ID="Image1" runat="server" Height="35px" Width="120px" ImageUrl=<%#DataBinder.Eval(Container.DataItem,"picPath") %>/>
</td>
</tr>
<tr>
<td align="center" colspan="3" style="height: 20px">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="select" ForeColor="Black" Width="172px"><%# DataBinder.Eval(Container.DataItem,"linkName") %></asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" ForeColor="Blue" HorizontalAlign="Center" />
</asp:DataList>
后台CS代码:
public partial class left : System.Web.UI.UserControl
{
SqlConnection sqlcon;
string strCon = "Data Source=localhost;Initial Catalog=db_sportnews;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string strLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
sqlcon = new SqlConnection(strCon);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from tblink where id='" + id + "'", sqlcon);
da.Fill(ds, "tblink");
DataRow[] row = ds.Tables[0].Select();
foreach (DataRow rs in row)
{
strLink = rs["linkAddress"].ToString();
}
Response.Write("<script language=javascript>window.open('http://" + strLink + "')</script>");
//bind();
}
//绑定
public void bind()
{
string sqlstr = "select top 4 * from tblink";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "tblink");
DataList1.DataSource = myds;
DataList1.DataKeyField = "ID";//主键
DataList1.DataBind();
sqlcon.Close();
}
}
前台Datalist的代码:
<asp:DataList ID="DataList1" runat="server" Height="1px"
Width="1px" OnItemCommand="DataList1_ItemCommand">
<ItemTemplate>
<table border="0" cellspacing="0" class="txt" style="width: 185px; height: 20px">
<tr>
<td colspan="3" style="height: 20px" align="center">
<asp:Image ID="Image1" runat="server" Height="35px" Width="120px" ImageUrl=<%#DataBinder.Eval(Container.DataItem,"picPath") %>/>
</td>
</tr>
<tr>
<td align="center" colspan="3" style="height: 20px">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="select" ForeColor="Black" Width="172px"><%# DataBinder.Eval(Container.DataItem,"linkName") %></asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
<HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
Font-Underline="False" ForeColor="Blue" HorizontalAlign="Center" />
</asp:DataList>
后台CS代码:
public partial class left : System.Web.UI.UserControl
{
SqlConnection sqlcon;
string strCon = "Data Source=localhost;Initial Catalog=db_sportnews;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
string strLink = "";
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
sqlcon = new SqlConnection(strCon);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from tblink where id='" + id + "'", sqlcon);
da.Fill(ds, "tblink");
DataRow[] row = ds.Tables[0].Select();
foreach (DataRow rs in row)
{
strLink = rs["linkAddress"].ToString();
}
Response.Write("<script language=javascript>window.open('http://" + strLink + "')</script>");
//bind();
}
//绑定
public void bind()
{
string sqlstr = "select top 4 * from tblink";
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "tblink");
DataList1.DataSource = myds;
DataList1.DataKeyField = "ID";//主键
DataList1.DataBind();
sqlcon.Close();
}
}
解决方案 »
- keyDown事件问题
- DevExpress.XtraGrid.Views.BandedGrid应用问题?
- C# DataSet导出xml 批处理(循环)得怎么处理
- 数据写入数据库,大家是怎么写的,用语句还是Dataset呀?
- 事件的问题?
- 求一个调用存储过程返回DataSet的方法???
- dataset问题(在线等)
- 关于猴子选大王代码的困惑
- 实在是没分了,大家发扬一下风格帮帮我:如何获取自己的路径,比如:D:\MY.EXE
- 问一个问题,请问,安装程序的向导是怎么实现的(仅窗体)。怎么能让在一个窗体里面,不停的点击下一步,出现不同的内容,然而全是在同一
- 如何获得开机用了多少时间?
- ◆大家来看看,winform窗体位置问题◆
就是在DataList1_ItemCommand方法中,添加一行代码中,添加一个断点,右击就会看到了