--------- 这是一个可分页datagrid的代码 -------- <asp:DataGrid AllowCustomPaging="True" AllowPaging="True" AutoGenerateColumns="False" CellPadding="6" id="DataGrid1" PagerStyle-Mode="NumericPages" PageSize="1000" runat="server" ShowFooter="True" OnPageIndexChanged="Grid_Change">
<AlternatingItemStyle Font-Size="Smaller" Font-Names="Verdana,Arial,Helvetica,sans-serif" BackColor="#E5E5E5"></AlternatingItemStyle>
<ItemStyle Font-Size="Smaller" Font-Names="Verdana,Arial,Helvetica,sans-serif" BackColor="#F2F2F2"></ItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Bold="True" HorizontalAlign="Center" ForeColor="#3D3DB6" BackColor="#E8EBFD"></HeaderStyle>
<FooterStyle Font-Size="Smaller" Font-Names="Verdana,Arial,Helvetica,sans-serif" Font-Bold="True" HorizontalAlign="Center" ForeColor="#3D3DB6" BackColor="#E8EBFD"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="序号" ReadOnly="True" HeaderText="序号" FooterText="序号" />
<asp:BoundColumn DataField="msisdn" ReadOnly="True" HeaderText="号码" FooterText="号码"></asp:BoundColumn>
<asp:BoundColumn DataField="quxian" ReadOnly="True" HeaderText="区县" FooterText="区县"></asp:BoundColumn>
<asp:BoundColumn DataField="zhuangtai" ReadOnly="True" HeaderText="状态" FooterText="状态"></asp:BoundColumn>
<asp:BoundColumn DataField="agent_id" ReadOnly="True" HeaderText="代理商编码" FooterText="代理商编码"></asp:BoundColumn>
<asp:BoundColumn DataField="create_date" ReadOnly="True" HeaderText="开户时间" FooterText="开户时间"></asp:BoundColumn>
<asp:BoundColumn DataField="ruwangleixing" ReadOnly="True" HeaderText="入网类型" FooterText="入网类型"></asp:BoundColumn>
</Columns>
<PagerStyle NextPageText="向前" Font-Size="Smaller" Font-Names="Verdana,Arial,Helvetica,sans-serif" PrevPageText="向后" BackColor="White" PageButtonCount="30" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
dgts_t.MappingName = "表名"二、System.Windows.Forms.DataGridTextBoxColumn dgtbc_1 = new System.Windows.Forms.DataGridTextBoxColumn();\\可以添加想要显示的数据列三、dgtbc_1.HeaderText=“显示列名”
dgtbc_1.MappingName=“数据集中的列”四、dgts_t.GridColumnStyles.Add(dgtbc_1);五、this.dataGrid.TableStyles.add(dgts_t);
private void FormatGrid()
{
//格式化表格
System.Windows.Forms.DataGridTableStyle dgts_t = new System.Windows.Forms.DataGridTableStyle();
dgts_t.MappingName = "表名"; System.Windows.Forms.DataGridTextBoxColumn dgtbc_1 = new System.Windows.Forms.DataGridTextBoxColumn(); //可以添加想要显示的数据列 dgtbc_1.HeaderText="显示列名";
dgtbc_1.MappingName="数据集中的列"; dgts_t.GridColumnStyles.Add(dgtbc_1);
dataGrid1.TableStyles.Add(dgts_t);
}
its MappingName to the TableName of a DataTable. */
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "default";
ts1.AllowSorting = false; /* Add a GridColumnStyle and set its MappingName
to the name of a DataColumn in the DataTable.
Set the HeaderText and Width properties. */
DataGridTextBoxColumn ID = new DataGridTextBoxColumn();
ID.MappingName = "Fid";
ID.HeaderText = "PR No";
ID .ReadOnly = true;
ID.Width = 120;
// ID .TextBox.AutoSize = true;
// ts1.PreferredColumnWidth = ID .TextBox.Width;
ts1.GridColumnStyles.Add(ID); // Add the DataGridTableStyle objects to the collection.
dataGrid1.TableStyles.Add(ts1);
怎么大家问一样的问题啊,唉,我自己的问题却不能解决
表头什么时候可以显示出来啊!另外如何手工添加记录行?(看来分数给的少了),我随后加!
应该是可以的呀!
问下你,你首先填充了数据集吗??
填充了数据集后,再用dataGrid.DataBindings(this.dataSet,"表名")才能显示的!如何手工添加记录行?
用dataSet.Tables[0].NewRow 就能做到!!