如何使用复选框更新gridview中的行 [英] how to update a row in gridview using checkbox
问题描述
我在asp.net中放置了一个gridview,在模板项字段中放置了一个复选框.asp Web表单中还有一个按钮.网格的选中行应更新为oracle数据库(表)当我单击按钮时.我是asp.net的新手.所以请帮助我..提前谢谢...
i had placed a gridview in asp.net and in template item field i had placed a check box.there is also a button in my asp web form.checked row of the grid should be updated in to oracle database(table) when i click the button.i am kind of new to asp.net .so please help me..thanks in advance...
推荐答案
取一个隐藏字段并放入除了复选框,并为其分配rowindex.
take one hiddenfield and put besides checkbox and assign rowindex to it.
<asp:checkbox id="yourcheckbox/" xmlns:asp="#unknown"><asp:hiddenfield runat="server" id="hidRowIndex" value="<%# Container.DataItemIndex %>" /></asp:checkbox>
并使用
进行检索
and retrieve using
protected void btnLink_Click(object sender, EventArgs e) { foreach (GridViewRow row in gvAllocated.Rows) { if (((CheckBox)row.FindControl("chkLink")).Checked) {
int index = (((HiddenField)row.FindControl("hidRowIndex")).Value;
// here you can acess your other values using rowidnex
} } }
尝试以下方法:
Try this one:
CheckBox chk;
int ID = 0;
foreach(GridViewRow row in GridView1.Rows)
{
chk = (CheckBox)row.Cells[0].FindControl("chkboxid"); //chkboxid is the ID of the checkbox control in asp.net inside template field
if(chk.Selected == true)
{
ID = Convert.ToInt32(row.Cells[1].Text);
}
}
其中Cells [0]是复选框,而Cells [1]是所选项目的ID.
然后使用ID作为查询的输入参数来更新...
如果这解决了您的问题,请标记为答案
问候,
爱德华
Wherein Cells[0] is the checkbox and Cells[1] is the ID of the selected item.
Then use ID as an input parameter for your query to update...
Please mark as answer if this solved your problem
Regards,
Eduard
这篇关于如何使用复选框更新gridview中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!