没有提示任何错误,网页能够出现,,但是点击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") %>/>
                            &nbsp;
                        </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();
    }
    
}

解决方案 »

  1.   

    如此说来,那就是DataList1_ItemCommand可能没有被执行你在这个方法里面断点或是log一下看
      

  2.   

    Response.Write??? 你是不是应该用添加子控件的方式。
      

  3.   


    就是在DataList1_ItemCommand方法中,添加一行代码中,添加一个断点,右击就会看到了
      

  4.   

    它的Response.Write是用来生成js脚本,以打开新窗口到另一个位置的
      

  5.   

    昨天又弄了一天,还是没解决,有没有高手贴段代码上来看看,如果前台我依然是用Datalist的话,怎样写后台代码能实现,将数据库中的超链接图片、地址这些显示出来,单击后能链接到相关网页。