循环复选框以获取asp.net c中的值时出现问题# [英] Problem when Looping checkbox to get values in asp.net c#

查看:61
本文介绍了循环复选框以获取asp.net c中的值时出现问题#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Coders,



我在gridview复选框中有多个插入问题。

i在设计中有隐藏字段traID我也是有复选框。

一旦用户选择复选框并单击按钮,需要将两个值传递给另一个函数。



这是代码Req_Click。我当时只能传递一个记录。



当用户使用复选框多个记录选择一行时,要发送给函数的值

如何实现这个?

我有InsertRecord函数,我发送这两个值来将记录插入到SQL数据库中。



Hello Coders,

I have a problem in gridview checkbox multiple inserts.
i have a Hidden field traID in design and also i have checkbox.
Once user select checkbox and click on button Req two values to be passed to the another function.

Here is code of Req_Click. where in i able to pass only one record at the time.

When user select a row using checkbox multiple records, values to be sent to function
how can implement this ?
I have InsertRecord function where I send these two values to insert record into the SQL database.

protected void btnReq_Click(object sender, EventArgs e)
{
foreach(GridViewRow dg in gvw_tdetails.Rows)
{
HiddenField hd = dg.Cells[6].FindControl("traID") as HiddenField;
CheckBox chkBox = (CheckBox)dg.FindControl("checkbox");
If (chkBox.Checked && chkBox!=null)
{
string tid = ((Label)dg.Cells[0].FindControl("lblTempID")).Text;
string txid = hd;
InsertRecord(tid,txid);
}
 
}
}

推荐答案

你必须创建一个结构将保存您的数据和某些集合(无论是列表,集合,XML文件等),您将传递给您的插入。



如果您正在使用SQL服务器,您可以将XML作为参数发送到存储过程并从XML进行批量插入。
You have to create a structure that will hold your data and some kind of collection (be it list, collection, XML file etc) that you will pass to your insert.

If you're using SQL Server, you can send XML as parameter to stored procedure and do bulk insert from XML.


Hostrings - 尽管可能性非常小,为什么我们不检查这个 - 是否是您的InsertRecord方法进展顺利,它会触发网格重新绑定?如果是这样,那么你将松开所有网格行并且循环将不会进一步执行?
Hostrings - even though the possibility is very less, why don't we check this - Whether your InsertRecord methods went well and it triggers a grid rebind ?. if so, then you will loose all grids rows and the loop won't execute further ?


这篇关于循环复选框以获取asp.net c中的值时出现问题#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆