在同一页面如何获取id值
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
plAdd.Visible = false;
Panel1.Visible = true;
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "update")
{
int i = int.Parse(this.GridView1.DataKeys[index].Value.ToString());
this.TextBox1.Text = this.GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text.Trim();
this.TextBox2.Text = this.GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[1].Text.Trim(); }
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "update Bulletins set bulletinTitle='" + this.TextBox1.Text.Trim() + "',bulletinContent='" + this.TextBox2.Text.Trim() + "' where bulletinId='" + Request["i"] + "'"; SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Label1.Text = "修改成功";
Bind();
}
<asp:GridView id="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="bulletinId" HorizontalAlign="Center"
CellSpacing="1" BackColor="White" PageSize="5"
onrowcommand="gvBulletin_RowCommand">
<Columns>
<asp:BoundField DataField="bulletinTitle" HeaderText="标题" />
<asp:BoundField DataField="bulletinContent" HeaderText="内容" />
<asp:BoundField DataField="bulletinTime" HeaderText="发布日期" />
<asp:ButtonField CommandName="update" HeaderText="操作" Text="编辑" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<HeaderStyle Font-Bold="True" BackColor="#6AC0FF"
ForeColor="White"></HeaderStyle>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
</asp:GridView>
用GridView1绑定公告信息,点击编辑按钮,此条信息的值在文本框中出现,呈现编辑状态,但为什么不能修改?单步调试时发现bulletinId值为空,即bulletinId=""。如何才能正确获取该条信息的bulletinId值呢?在线等,急! --------------------编程问答-------------------- 建议看下我的一遍博客
http://blog.csdn.net/keymo_
其中的“学习笔记4”。 --------------------编程问答-------------------- 一篇博客 --------------------编程问答-------------------- 直接用sqldatasouse控件和gridview控件
不用后台代码不也能实现编辑功能吗? --------------------编程问答--------------------
谢谢!这个问题解决了,想请教楼主一个问题。如何把公告信息以滚动形式显示在页面上呢。从右向左滚动,点击可以进入详细的页面查看。
补充:.NET技术 , ASP.NET