继续求救
现在是这样,我打算在DataGrid的模板列中放入一个自定义控件,绑定自定义控件的属性值,但是翻页的时候,绑定的属性值就丢失了.
这个问题已经迷茫我两天了.麻烦那位大哥给我帮帮忙.最好给我个简单的例子,在一个只有一列的DataGrid中放入一个非常简单的自定义控件,只要翻页不出错就可以.分不多了,麻烦大哥哥们帮帮忙!
现在是这样,我打算在DataGrid的模板列中放入一个自定义控件,绑定自定义控件的属性值,但是翻页的时候,绑定的属性值就丢失了.
这个问题已经迷茫我两天了.麻烦那位大哥给我帮帮忙.最好给我个简单的例子,在一个只有一列的DataGrid中放入一个非常简单的自定义控件,只要翻页不出错就可以.分不多了,麻烦大哥哥们帮帮忙!
-----------------------------<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 72px; POSITION: absolute; TOP: 56px" runat="server"
Width="224px" AutoGenerateColumns="False" PageSize="8" AllowPaging="True">
<Columns>
<asp:TemplateColumn HeaderText="编号">
<ItemTemplate>
<uc1:test id="Test1" runat="server" Emp='<%# DataBinder.Eval(Container.DataItem,"emp_id") %>'>
</uc1:test>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:DataGrid></FONT>
</form>
</body>
----------------------------------
namespace aspTest
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.DataBinderToDataGird();
}
} public void DataBinderToDataGird()
{
SqlConnection conn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=123;");
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from employee",conn);
DataTable Dt = new DataTable();
sda.Fill(Dt);
this.DataGrid1.DataSource = Dt.DefaultView;
this.DataGrid1.DataBind();
conn.Close();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.DataBinderToDataGird(); }
}
}
----------------------------
namespace aspTest
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class test : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected string Emp_id;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
SqlConnection conn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=123;");
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from employee where emp_id='"+Emp_id+"'",conn);
DataTable Dt = new DataTable();
sda.Fill(Dt);
this.TextBox1.Text = Dt.Rows[0]["pub_id"].ToString();
}
} public string Emp
{
set
{
this.Emp_id = value;
}
}
}
}