DataGrid中用超级链接列,在模板向导中设置

解决方案 »

  1.   

    to=qingren:
      你好你好,我已经在DataGrid中设好了这一项,现在主要是不知道这样在连接到的这一页怎样根据ID号绑定数据,而且根据不同的ID好绑定不同的数据,请多多赐教,谢谢
      

  2.   

    在超级链接魔板列中设置url为你要显示详细信息的页面如detail.aspx,url字段为你想要传输的id字段名,url格式字符串为Detail.aspx?id={0},在Detail.aspx页面中使用request["id"]取得该参数值,即可实现。文本及文本字段部分是表示你希望在该列中显示的字段内容。
      

  3.   

    //首先帮定你的键字段
    this.DataGrid1.DataKeyField=cashtbl.columnName["id"];
    //然后超链列通过id参数链接
    ((HyperLinkColumn)this.DataGrid1.Columns[0]).DataNavigateUrlFormatString="CashFlowInputForm.aspx?oid={0}&isnew=1";
      

  4.   

    kingwood2000(kingwood) :
    request["id"]是在detail.aspx的pageload中写吗?
    能不能告诉我怎么在detail.aspx.cs中写完整的绑定代码。谢谢!
      

  5.   

    to=crocus(常): 
    你好,请问这段代码写在哪个页面的哪个位置?我开始一看你的代码有点迷糊,能不能给我一个具体的代码环境?我现在主要是不知道在点击超级连接弹出的窗口中怎样写代码,能不能帮帮我?谢谢!
      

  6.   

    一般在PAGE_LOAD的
    if(!IsPostBack)
    {
    //your code
    }
    中。
    string userid = Request["id"].ToString();
    然后是你的数据绑定语句,一般如下:
    string sqlStr = "SELECT * FROM YOURTABLE WHERE ID字段 = @userid"
    SqlConnection myConn = new SqlConnection(connStr);
    SqlDataAdapter myDA = new SqlDataAdapter(sqlStr,myConn);myDA.SelectCommand.Parameters.Add("@userid",SqlDbType.你的id字段类型,长度);
    myDA.SelectCommand.Parameters["@userid"].Value = userid;

    DataSet myDS = new DataSet();
    myDA.Fill(myDS,"YOURTABLE");你的数据绑定控件.DataSource = myDS.Tables["YOURTABLE"].DefaultView;
    你的数据绑定控件.DataBind();
      

  7.   

    由于在前页的超链列已传递了参数id
    在弹出的窗口中,你可以获取id,然后根据获取的id再查询
    oid=Request.QueryString["oid"].Trim();
    isnew=Request.QueryString["isnew"].Trim();
      

  8.   

    string icount= Request["icount"].ToString();
      Label1.Text=icount;
    int Count=int.Parse(icount);
    //  this.DBopen();
    string strSql=@"SELECT * FROM mytable WHERE icount=@icount";
    string strSql2="SELECT * FROM mytable WHERE icount='" + Count.ToString()+"'";
     DataTable tb=this.DBQuery(strSql2);
     TextBox11.Text=tb.Rows[0]["Employeename"].ToString();
    TextBox8.Text=tb.Rows[0]["Logoid"].ToString();
    TextBox4.Text =tb.Rows[0]["Telephone"].ToString();
    TextBox6.Text=tb.Rows[0]["Mobilphone"].ToString();
    TextBox5.Text=tb.Rows[0]["Fax"].ToString();
    string @strEmployeeid=tb.Rows[0]["Employeeid"].ToString();
    int Employeeid=int.Parse(@strEmployeeid);
    //  this.DBopen();
    string strSql=@"SELECT * FROM mytable WHERE Employeeid='"+Employeeid.ToString()+"'";
    DataTable tbl=this.DBQuery(strSql);
    TextBox11.Text=tbl.Rows[0]["Employeename"].ToString();
    TextBox7.Text=tbl.Rows[0]["Homeaddress"].ToString();
    TextBox10.Text=tbl.Rows[0]["Email"].ToString(); 
    TextBox2.Text=tbl.Rows[0]["Dname"].ToString();                
    TextBox1.Text=tbl.Rows[0]["Age"].ToString();
    //if(tbl.Rows[0]["property"].ToString()=="1")  property.Text="";
    //else             property.Text="";我想用使用以上的这段代码来实现我所需要的功能,我是想点击超级连接后可以到这个窗体,这个窗体的信息又是存于另一个与开始的DataGrid不同的数据表,而表中的信息是在不同的控件中显示出来,以上的数据字段都是库表中的字段,但是实现不了,不知道这段代码什么地方错了,请继续指点迷津,谢谢。
      

  9.   

    kingwood2000(kingwood) 大哥的这段代码如果是在超级连接的页面中是DataGrid这样的控件来显示绑定数据的话是比较方便的,但我想利用数据库中的一个表在超级连接窗体中的多个控件上显示数据,比如TextBox,DropDownList,等多个控件上显示我的数据,应该对那段代码怎么该?????高手指教,小弟已经为这个简单的问题忙了一天了,我想一定是菜鸟一思考,高手就发笑吧!请多多赐教,
      

  10.   

    不好意思这两天忙,没上网。你的DBQuery方法是如何实现的?
      

  11.   

    <Columns>
             <asp:BoundColumn DataField="ForumId" SortExpression="LastVisitDate" HeaderText="ID">
                       <HeaderStyle Width="5px"></HeaderStyle>
             </asp:BoundColumn>
    <asp:BoundColumn Visible="False" DataField="ForumName" SortExpression="ForumName"></asp:BoundColumn>
    <asp:TemplateColumn SortExpression="LastVisitDate" HeaderText="Last visit">
    <HeaderStyle Width="400px"></HeaderStyle>
    <ItemTemplate>
    <asp:HyperLink id="hlForum" NavigateUrl='<%# "ForumDetail.aspx?ForumId=" + Server.UrlEncode(DataBinder.Eval(Container.DataItem, "ForumId").ToString()) %>' Runat="server">
    <%#Server.HtmlEncode(DataBinder.Eval(Container.DataItem, "ForumName").ToString()) %>
    </asp:HyperLink>
    </ItemTemplate>
    </asp:TemplateColumn>