gridview获取RadioButton选中问题
相关参考:http://topic.csdn.net/u/20120704/15/1b73d3dd-36fb-4ff9-841a-84dac0bb3b60.html大表单中嵌套一个gridview,其中使用RadioButton实现性别选择,在大表单新增过程中,嵌套的gridview已经实现新增加、删除,然后存入数据库,都没有问题。现在问题在于编辑大表单,所有数据从数据库读取出来绑定到相关控件,gridview也要绑定从数据库读出的数据,显示,然后对其进行修改、删除,然后存入数据库,用我以下的方法该如何实现gridview编辑。哪里开始绑定数据?更新如何实现?
大表单新增过程,gridview具体实现如下面:
--------------------编程问答-------------------- ..神马跟神马啊 你到底要干嘛 看得我头晕 --------------------编程问答-------------------- 没说清楚吗?就是表单提交后,需要实现编辑操作,嵌套的gridview要绑定数据并能实现删除与更新。 --------------------编程问答-------------------- 没说清楚吗?就是表单提交后,需要实现编辑操作,嵌套的gridview要绑定数据并能实现删除与更新。 --------------------编程问答-------------------- 继续求助! --------------------编程问答--------------------
protected void TablesT1()
{
ds.Tables.Add("T1");
ds.Tables["fb3"].Columns.Add("BNo", typeof(string));
ds.Tables["fb3"].Columns.Add("men", typeof(bool));
ds.Tables["fb3"].Columns.Add("women", typeof(bool));
}
//gridview绑定数据
public void BindGrid()
{
this.GridView1.DataSource = ds.Tables["T1"];
this.GridView1.DataBind();
}
//将gridview输入内容暂存dataset
public void ReBind()
{
foreach (GridViewRow gridrow in this.GridView3.Rows)
{
DataRow row = ds.Tables["T1"].NewRow();
row = ds.Tables["fb3"].Rows[gridrow.DataItemIndex];
row["BNo"] = ((TextBox)(gridrow.FindControl("BNo"))).Text;
row["men"] = ((RadioButton)(gridrow.FindControl("CR"))).Checked;
row["women"] = ((RadioButton)(gridrow.FindControl("Maj"))).Checked;
}
}
private void SaveDate()
{
foreach (DataRow row in ds.Tables["T1"].Rows)
{
//数据入库
}
}
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
if ("add" == e.CommandName)
{
//新增数据
}
if ("del" == e.CommandName)
{
//删除数据
}
}
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
if ("add" == e.CommandName)
{
//新增数据
}
if ("del" == e.CommandName)
{
//删除数据
}
if ("edit" == e.CommandName)
{
//修改数据 }
}
//其实gridview有自带的删除、编辑事件!(注意我这里的GvUsers就是Gridview)
protected void GvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Users user = new Users();
int uid = Convert.ToInt32(GvUsers.DataKeys[e.RowIndex].Value);
string uname = ((TextBox)(GvUsers.Rows[e.RowIndex].Cells[1].Controls[0])).Text;
string truename=((TextBox)(GvUsers.Rows[e.RowIndex].Cells[2].Controls[0])).Text;
string pwd=((TextBox)(GvUsers.Rows[e.RowIndex].Cells[3].Controls[0])).Text;
int dptid = Convert.ToInt32(((DropDownList)(GvUsers.Rows[e.RowIndex].Cells[4].FindControl("DropDpt"))).SelectedValue);
if (user.USer_Edit(uid,uname,truename,pwd,dptid))
{
GvUsers.EditIndex = -1;
UserBind();
}
else
{
Common.ShowMessage.Show(Page, "true", "修改失败!", "AllUsers.aspx");
}
}
--------------------编程问答-------------------- 谢谢,我这种做法比较麻烦,关键是应该先读出已有数据到data table中,然后进行更新,删除,新增操作。 --------------------编程问答-------------------- 继续求助 --------------------编程问答-------------------- RadioButton 每行为一组 先默认选中一个
--------------------编程问答--------------------
我是要从数据库读出数据来绑定到RadioButton,默认选中有什么意义 --------------------编程问答-------------------- 没人遇到过? --------------------编程问答-------------------- 继续求助
补充:.NET技术 , ASP.NET