Hi,
I am working on a project in asp.net with c#.
I take data from mysql database and with this data set populate GridView
I want to dynamically generate a new Row in GridView respecting the sequence of the column `sID_contents`
When the value of column `sID_contents` is greater than zero I can add a new row to the GridView
This is my data
-- ----------------------------
-- Table structure for t_contents
-- ----------------------------
DROP TABLE IF EXISTS `t_contents`;
CREATE TABLE `t_contents` (
`contents` varchar(1000) DEFAULT NULL,
`sID_contents` int(11) DEFAULT NULL,
`sUnita` varchar(255) DEFAULT NULL,
`sID` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`sID`) USING BTREE,
UNIQUE INDEX `contents`(`contents`) USING BTREE
) ENGINE = InnoDB;
-- ----------------------------
-- Records of t_contents
-- ----------------------------
INSERT INTO `t_contents` VALUES ('Near', 0, 'D1C', 1);
INSERT INTO `t_contents` VALUES ('Management', 0, 'D1C', 2);
INSERT INTO `t_contents` VALUES ('Miss', 0, 'D1C', 3);
INSERT INTO `t_contents` VALUES ('Near 1', 1, 'D1C', 4);
INSERT INTO `t_contents` VALUES ('Management 1', 1, 'D1C', 5);
INSERT INTO `t_contents` VALUES ('Miss 1', 1, 'D1C', 6);
INSERT INTO `t_contents` VALUES ('Near 2', 2, 'D1C', 7);
INSERT INTO `t_contents` VALUES ('Management 2', 2, 'D1C', 8);
INSERT INTO `t_contents` VALUES ('Miss 2', 2, 'D1C', 9);
public partial class gv : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("contents"),
new DataColumn("sID_contents"),
new DataColumn("sUnita"),
new DataColumn("sID")
});
dt.Rows.Add("Near", 0, "D1C", 1);
dt.Rows.Add("Management", 0, "D1C", 2);
dt.Rows.Add("Miss", 0, "D1C", 3);
dt.Rows.Add("Near 1", 1, "D1C", 4);
dt.Rows.Add("Management 1", 1, "D1C", 5);
dt.Rows.Add("Miss 1", 1, "D1C", 6);
dt.Rows.Add("Near 2", 2, "D1C", 7);
dt.Rows.Add("Management 2", 2, "D1C", 8);
dt.Rows.Add("Miss 2", 2, "D1C", 9);
gvitems.DataSource = dt;
gvitems.DataBind();
}
}
}
<asp:GridView ID="gvitems" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="contents" HeaderText="contents" ItemStyle-Width="30" />
<asp:BoundField DataField="sID_contents" HeaderText="sID_contents" ItemStyle-Width="150" />
<asp:BoundField DataField="sUnita" HeaderText="sUnita" ItemStyle-Width="150" />
<asp:BoundField DataField="sID" HeaderText="sID" ItemStyle-Width="150" />
</Columns>
</asp:GridView>