×

gridview控件增删改查 添加 rid

ASP.NET 中GridView控件怎么修改添加数据?gridview控件的使用和说明

admin admin 发表于2022-06-21 14:06:07 浏览123 评论0

抢沙发发表评论

ASP.NET 中GridView控件怎么修改添加数据


我有个现成的完整实例:

//前台GridView
《asp:GridView ID=“gv_friendlink“ runat=“server“ AutoGenerateColumns=“False“
onrowcancelingedit=“gv_friendlink_RowCancelingEdit“
onrowediting=“gv_friendlink_RowEditing“
onrowupdating=“gv_friendlink_RowUpdating“ CellPadding=“4“
ForeColor=“#333333“ GridLines=“None“ Font-Names=“楷体_GB2312“ Font-Size=“Medium“
ShowFooter=“True“ onrowdeleting=“gv_friendlink_RowDeleting“ Width=“758px“》
《Columns》
《asp:TemplateField》
《HeaderTemplate》网站名称《/HeaderTemplate》
《ItemTemplate》
《asp:Label ID=“Labelname“ runat=“server“ style=“margin-left:10px;“ Width=“240“ Text=’《%#Eval(“Fname“) %》’》《/asp:Label》
《/ItemTemplate》
《EditItemTemplate》
《asp:TextBox ID=“txtname“ runat=“server“ style=“margin-left:10px;“ Width =“200px“ Text=’《%#Eval(“Fname“) %》’》《/asp:TextBox》
《/EditItemTemplate》
《/asp:TemplateField》
《asp:TemplateField》
《HeaderTemplate》网站完整的网址《/HeaderTemplate》
《ItemTemplate》
《asp:HyperLink ID=“HyperLink1“ runat=“server“ style=“margin-left:10px;“ Width =“230px“ NavigateUrl=’《%#Eval(“Furl“) %》’ Target=“_blank“》《%#Eval(“Furl“) %》《/asp:HyperLink》
《%--《asp:Label ID=“Labelurl“ runat=“server“ Text=’《%#Eval(“Furl“) %》’》《/asp:Label》--%》
《/ItemTemplate》
《EditItemTemplate》
《asp:TextBox ID=“txturl“ runat=“server“ Text=’《%#Eval(“Furl“) %》’ 》《/asp:TextBox》
《/EditItemTemplate》
《/asp:TemplateField》
《asp:TemplateField》
《HeaderTemplate》优先级《/HeaderTemplate》
《ItemTemplate》
《center 》《asp:Label ID=“Labelpriority“ runat=“server“ Text=’《%#Eval(“FPriority“) %》’》《/asp:Label》《/center》
《/ItemTemplate》
《EditItemTemplate》
《asp:TextBox ID=“txtpriority“ runat=“server“ Text=’《%#Eval(“FPriority“) %》’ 》《/asp:TextBox》
《/EditItemTemplate》
《/asp:TemplateField》
《asp:TemplateField》
《HeaderTemplate》   编辑  《/HeaderTemplate》
《ItemTemplate》
《center》《asp:Button ID=“edit“ runat=“server“ Text=“编辑“ CommandName=“edit“ /》《/center》
《/ItemTemplate》
《EditItemTemplate》
《asp:Button ID=“update“ runat=“server“ Text=“更新“ CommandName=“Update“ /》
《asp:Button ID=“cancel“ runat=“server“ Text=“取消“ CommandName=“Cancel“ /》
《/EditItemTemplate》
《/asp:TemplateField》
《asp:TemplateField》
《HeaderTemplate》   删除  《/HeaderTemplate》
《ItemTemplate》
《center》《asp:Button ID=“delete“ runat=“server“ Text=“删除“ CommandName=“delete“ OnClientClick=“return confirm(’真的要删除吗?’);“ /》《/center》
《/ItemTemplate》
《EditItemTemplate》《/EditItemTemplate》
《/asp:TemplateField》
《/Columns》
《FooterStyle Font-Bold=“True“ ForeColor=“White“ /》
《RowStyle BackColor=“#F7F6F3“ ForeColor=“#333333“ HorizontalAlign=“Left“ /》
《EditRowStyle BackColor=“#999999“ /》
《SelectedRowStyle BackColor=“#E2DED6“ Font-Bold=“True“ ForeColor=“#333333“ /》
《PagerStyle BackColor=“#284775“ ForeColor=“White“ HorizontalAlign=“Center“ /》
《HeaderStyle BackColor=“LightGray“ Font-Bold=“True“ ForeColor=“White“ /》
《AlternatingRowStyle BackColor=“White“ ForeColor=“#284775“ /》
《/asp:GridView》
《br /》
《asp:TextBox ID=“txt_fname“ runat=“server“ Width=“265px“》《/asp:TextBox》
 《asp:TextBox ID=“txt_furl“ runat=“server“ Width=“225px“》《/asp:TextBox》
 
《asp:TextBox ID=“txt_fpriority“ runat=“server“ Width=“85px“》《/asp:TextBox》
 《asp:Button ID=“btn_insert“ runat=“server“ Text=“添加链接“ onclick=“btn_insert_Click“ /》

//后台代码

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
((Label)Master.FindControl(“lbTitle“)).Text = “友情链接管理“;
bind();
}

}
protected void bind()
{
System.Data.DataSet ds = new zdxk.BLL.friendlinks().GetAllList();
gv_friendlink.DataKeyNames = new string { “id“ };
gv_friendlink.DataSource = ds;
gv_friendlink.DataBind();
}

protected void gv_friendlink_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gv_friendlink.EditIndex = -1;
bind();
}

protected void gv_friendlink_RowEditing(object sender, GridViewEditEventArgs e)
{
gv_friendlink.EditIndex = e.NewEditIndex;
bind();
}

protected void gv_friendlink_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
zdxk.Model.friendlinks link = new zdxk.Model.friendlinks();
link.id = Convert.ToInt64(gv_friendlink.DataKeys[e.RowIndex].Value);
link.fname = ((TextBox)(gv_friendlink.Rows[e.RowIndex].FindControl(“txtname“))).Text.ToString();
link.furl = ((TextBox)(gv_friendlink.Rows[e.RowIndex].FindControl(“txturl“))).Text.ToString();
link.fpriority = Convert.ToInt32(((TextBox)(gv_friendlink.Rows[e.RowIndex].FindControl(“txtpriority“))).Text);
if (link.fname == ““ || link.furl == ““ || link.fpriority 《= 0)
{
MessageBox.Show(this, “优先级必须大于0,请填写完整信息!“);
e.Cancel = true;
}
;
if (new zdxk.BLL.friendlinks().Update(link))
{
MessageBox.Show(this, “更新成功!“);
gv_friendlink.EditIndex = -1;
bind();
}
else MessageBox.Show(this, “更新失败,请重试!“);
}
catch (Exception)
{
MessageBox.Show(this,“请输入正确的内容!谢谢!“); e.Cancel = true;
}

}

protected void btn_insert_Click(object sender, EventArgs e)
{
if (txt_fname.Text == ““ || txt_fpriority.Text == ““ || txt_furl.Text == ““)
{
MessageBox.Show(this, “请填写完整链接信息!“); return;
}
try
{
zdxk.Model.friendlinks link = new zdxk.Model.friendlinks();
link.fname = txt_fname.Text;
link.furl = txt_furl.Text;
link.fpriority = Convert.ToInt64(txt_fpriority.Text);
if (link.fpriority 《= 0)
{
MessageBox.Show(this, “优先级必须大于0,请填写正确的数据!“);
return;
}
if (new zdxk.BLL.friendlinks().Add(link) 》 0)
{
txt_fname.Text = txt_fpriority.Text = txt_furl.Text = ““;
MessageBox.Show(this, “添加成功!“);
bind();
}
else
{
MessageBox.Show(this, “添加失败,请重试!“);
}
}
catch
{
MessageBox.Show(this, “优先级必须大于0,请填写正确的数据!“);
return;
}
}

protected void gv_friendlink_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
long Id = Convert.ToInt64(gv_friendlink.DataKeys[e.RowIndex].Value);
if (new zdxk.BLL.friendlinks().Delete(Id))
{
MessageBox.Show(this, “删除成功!“);
bind();
}
else
{
MessageBox.Show(this, “删除失败,请重试!“);
}
}

gridview控件的使用和说明


GridView控件事件详解
RowCommand
在 GridView 控件中单击某个按钮时发生。此事件通常用于在该控件中单击某个按钮时执行某项任务。

PageIndexChanging
在单击页导航按钮时发生,但在 GridView 控件执行分页操作之前。此事件通常用于取消分页操作。
PageIndexChanged
在单击页导航按钮时发生,但在 GridView 控件执行分页操作之后。此事件通常用于在用户定位到该控件中不同的页之后需要执行某项任务时。
SelectedIndexChanging
在单击 GridView 控件内某一行的 Select 按钮(其 CommandName 属性设置为“Select”的按钮)时发生,但在 GridView 控件执行选择操作之前。此事件通常用于取消选择操作。
SelectedIndexChanged
在单击 GridView 控件内某一行的 Select 按钮时发生,但在 GridView 控件执行选择操作之后。此事件通常用于在选择了该控件中的某行后执行某项任务。
Sorting
在单击某个用于对列进行排序的超链接时发生,但在 GridView 控件执行排序操作之前。此事件通常用于取消排序操作或执行自定义的排序例程。
Sorted
在单击某个用于对列进行排序的超链接时发生,但在 GridView 控件执行排序操作之后。此事件通常用于在用户单击对列进行排序的超链接之后执行某项任务。
RowDataBound
在 GridView 控件中的某个行被绑定到一个数据记录时发生。此事件通常用于在某个行被绑定到数据时修改该行的内容。
RowCreated
在 GridView 控件中创建新行时发生。此事件通常用于在创建某个行时修改该行的布局或外观。
RowDeleting
在单击 GridView 控件内某一行的 Delete 按钮(其 CommandName 属性设置为“Delete”的按钮)时发生,但在 GridView 控件从数据源删除记录之前。此事件通常用于取消删除操作。
RowDeleted
在单击 GridView 控件内某一行的 Delete 按钮时发生,但在 GridView 控件从数据源删除记录之后。此事件通常用于检查删除操作的结果。
RowEditing
在单击 GridView 控件内某一行的 Edit 按钮(其 CommandName 属性设置为“Edit”的按钮)时发生,但在 GridView 控件进入编辑模式之前。此事件通常用于取消编辑操作。
RowCancelingEdit
在单击 GridView 控件内某一行的 Cancel 按钮(其 CommandName 属性设置为“Cancel”的按钮)时发生,但在 GridView 控件退出编辑模式之前。此事件通常用于停止取消操作。
RowUpdating
在单击 GridView 控件内某一行的 Update 按钮(其 CommandName 属性设置为“Update”的按钮)时发生,但在 GridView 控件更新记录之前。此事件通常用于取消更新操作。
RowUpdated
在单击 GridView 控件内某一行的 Update 按钮时发生,但在 GridView 控件更新记录之后。此事件通常用来检查更新操作的结果。
DataBound
此事件继承自 BaseDataBoundControl 控件,在 GridView 控件完成到数据源的绑定后发生。

求一篇有关桥梁的英语作文


Bridges are among the most important, and often the most spectacular, of all civil engineering works.
There are six main types of bridges: beam bridges, cantilever bridges, arch bridges, suspension bridges, cable-stayed bridges and truss bridges.
A bridge is designed for trains, pedestrian or road traffic, a pipeline or waterway for water transport or barge traffic. An aqueduct is a bridge that carries water, resembling a viaduct, which is a bridge that connects points of equal height. A road-rail bridge carries both road and rail traffic.
Bridges may be classified by how the forces of tension, compression, bending, torsion and shear are distributed through their structure. Most bridges will employ all of the principal forces to some degree, but only a few will predominate. The separation of forces may be quite clear. In a suspension or cable-stayed span, the elements in tension are distinct in shape and placement. In other cases the forces may be distributed among a large number of members, as in a truss, or not clearly discernible to a casual observer as in a box beam. Bridges can also be classified by their lineage, which is shown as the vertical axis on the diagram to the right.
-rid