关于使用datagrid的两个问题,help...

beansprout 2004-09-08 02:37:19
private void BindGrid()
{
this.myconn.FillDataSet(titleDataSet1);
this.DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
if(this.IsPostBack)
return;
BindGrid();
}
private void Button1_Click(object sender, System.EventArgs e)
{
this.DataGrid1.CurrentPageIndex=0;
this.myconn.SqlDataAdapter1.SelectCommand.CommandText="select * from title_gov where "+ddlsearchclass.SelectedValue+" like '%"+tbsearchkey.Text+"%'";
BindGrid();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}
我点击按钮button1的时候 DataGrid1显示出要查询的内容,DataGrid1将查询的记录分为4页,,当我点击第2页的时候,却跑到Page_Load时的第2页去了,怎么解决啊?help。。。
还有我怎么定义DataGrid1的行距啊?help。。
...全文
147 点赞 收藏 22
写回复
22 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
beansprout 2004-09-13
为什么把this.myconn.SqlDataAdapter1.SelectCommand.CommandText写到DataGrid1_PageIndexChanged就可以了???
回复
gcj304 2004-09-08
ark_matrix(matrix)方法差不多是对的
我以前也发生过这样的事
回复
binsky 2004-09-08
up!
回复
spgoal 2004-09-08
其实你这个程序的DATAGRID需要在不同条件下绑定两种数据集,是否可以这样:你用一个ViewState变量标示如果不按BUTTON的情况下和按了BUTTON的情况下的状态,然后根据ViewState变量的值来判断应该绑定哪个数据集
回复
beansprout 2004-09-08
还是要用dataview和rowfilter做查询??。。help。。
回复
beansprout 2004-09-08
是否查询不应该这样写??
回复
beansprout 2004-09-08
用if(!IsPostBack)
{
BindGrid();
}
还是不行,:( help。。。
回复
yichuan1982 2004-09-08
is(!Page.IsPostBack)

不然的话,每次页面自动进行帮顶,而不是你所查询出来的页面进行帮顶
回复
yichuan1982 2004-09-08
up
回复
spgoal 2004-09-08
同意ark_matrix(matrix) 的做法

修改行距,在“属性生成器”--》边框--单元格间距
回复
myxs 2004-09-08
重新帮定Dataset
回复
yichuan1982 2004-09-08
up
回复
beansprout 2004-09-08
如何修改?help。。
回复
swweng 2004-09-08
datagrid行距能设置么?
回复
ark_matrix 2004-09-08
修改这个
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}
回复
beansprout 2004-09-08
try..
回复
dejun1981 2004-09-08
up
回复
goody9807 2004-09-08
'得到数据视图,参数为要排序的列
Private Function GetDv(ByVal strSort As String) As DataView
'定义数据库连接
Dim dv As DataView
Dim CN As New SqlConnection()
Try
'初始化连接字符串
CN.ConnectionString = "data source=pmserver;
initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;"
CN.Open()
'从NorthWind得到orders表的数据
Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from orders", CN)
Dim ds As New DataSet()
adp.Fill(ds)
'得到数据视图
dv = ds.Tables(0).DefaultView
Catch ex As Exception
#If DEBUG Then
Session("Error") = ex.ToString()
Response.Redirect("../error.aspx") '跳转程序的公共错误处理页面
#End If
Finally
'关闭连接
CN.Close()
End Try
'排序
dv.Sort = strSort
Return dv
End Function

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
ViewState("strSort") = "orderid"
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End If
End Sub
'排序
Private Sub dgOrder_SortCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOrder.SortCommand
dgOrder.CurrentPageIndex = 0
'得到排序的列
ViewState("strSort") = e.SortExpression.ToString()
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub

'分页
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged
'得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub

回复
goody9807 2004-09-08
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgOrder" runat="server" Height="515px" Width="718px" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" BorderWidth="1px" BorderColor="#A0ABEB" PageSize="15" BorderStyle="Solid" BackColor="White" GridLines="Vertical" ForeColor="Black" AllowPaging="True" ShowFooter="True">
<SelectedItemStyle ForeColor="White" BackColor="Black"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BorderColor="#6876C5" BackColor="#6876C5"></HeaderStyle>
<FooterStyle ForeColor="White" BackColor="#6876C5"></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<FONT face="">
<asp:CheckBox id="Cb" runat="server"></asp:CheckBox></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="orderid" SortExpression="orderid" HeaderText="ID">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipCountry" SortExpression="ShipCountry" HeaderText="ShipCountry">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShippedDate" SortExpression="ShippedDate" HeaderText="ShippedDate" DataFormatString="{0:d}">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Freight" SortExpression="Freight" HeaderText="Freight">
<HeaderStyle Width="180px"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="ShipAddress" SortExpression="ShipAddress" HeaderText="ShipAddress">
<HeaderStyle Width="480px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" Position="TopAndBottom" BackColor="White" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</form>
回复
vzxq 2004-09-08
加个断点追踪一下
回复
加载更多回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2004-09-08 02:37
社区公告
暂无公告