检索Gridview数据为字符串 [英] Retrieve Gridview Data as String

查看:72
本文介绍了检索Gridview数据为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个Gridview,其中的列分别为Itemid,项目名称和Pnumber.
从具有相同Pnumber的行中获取项目ID和项目名称,并将结果作为字符串返回.

谁能告诉我该怎么做...

Hi All,

I have a gridview with columns as Itemid, item name, and Pnumber.
Fetch the item id and item name from the rows which are having same Pnumber and return the result as string.

can any one tell me how to do that...

推荐答案

好.因此,这听起来像是您的功课,而且好事是您对此一无所知.

可以有多种方法来做到这一点.一种简单的方法可以是:
1.遍历数据网格行
2.选择第一行Pnumber并检查其他行.如果找到相同的内容,则在字符串中添加详细信息.
3.维护已检查的Pnumber.这样您下次就不会重复相同的内容了.
4.对所有行执行这些操作.

立即尝试!
Ok. So this sounds like your homework and good thing is you have no idea about it.

There can be various ways to do it. One simple way can be:
1. Loop through the datagrid rows
2. Pick the first row Pnumber and check with other rows. If you find same add the details in a string.
3. Maintain the Pnumber already checked. So that you dont repeat the same next time.
4. Do these for all rows.

Try now!


您好,Sandeep,

我尝试过这种方式..但是得到的输出是..
Answer1Answer1%Answer2Answer1%Answer2%Answer3.我正在用相同的代码发送邮件.我必须发送9封邮件,但发送27封邮件..怎么办..



检查我的代码..

受保护的void通知(对象发送者,EventArgs e)
{
SPSite mysite =新的SPSite("sitename");
SPWeb MYWEB = mysite.OpenWeb();
SPList Rmslist = MYWEB.Lists ["list"];
SPListItemCollection Rmscollection = Rmslist.Items;
字符串Iitem = null;
字符串Iitemno = null;
字符串Iitemname = null;
试试
{
如果(ViewState ["CurrentTable"]!= null)
{
DataTable dt =(DataTable)ViewState ["CurrentTable"];
如果(dt.Rows.Count> 0)
{
for(int i = 0; i< dt.Rows.Count; i ++)
{
TextBox box1 =(TextBox)GridView2.Rows [i] .Cells [0] .FindControl("txtitems");
TextBox box2 =(TextBox)GridView2.Rows [i] .Cells [1] .FindControl("txtitemno");
TextBox box3 =(TextBox)GridView2.Rows [i] .Cells [2] .FindControl("txtitemname");
DropDownList ddl1 =(DropDownList)GridView2.Rows [i] .Cells [3] .FindControl("ddlplants");
DropDownList ddl2 =(DropDownList)GridView2.Rows [i] .Cells [4] .FindControl("ddlsloc");
TextBox box4 =(TextBox)GridView2.Rows [i] .Cells [5] .FindControl("txtpr");
//DropDownList ddl3 =(DropDownList)GridView2.Rows [i] .Cells [6] .FindControl("ddlreqstatus");
DropDownList ddl4 =(DropDownList)GridView2.Rows [i] .Cells [6] .FindControl("ddlitemstatus");
项目+ = box1.Text;
Iitemno + = box2.Text;
Iitemname + = box3.Text;
字符串prnum = box4.Text;
字符串工厂= ddl1.SelectedValue.ToString();
字符串位置= ddl2.SelectedValue.ToString();
字符串istatus = ddl4.SelectedValue.ToString();
字符串mId;

if((prnum!= string.Empty)&&(istatus =="PR Raised"))
{
foreach(Rmscollection中的SPListItem项)
{
if((plant == item ["Plant"].ToString())&&(Slocation == item ["Storesloc"].ToString()))
{
for(int j = 1; j< 10; j ++)
{
if(((item.Fields ["mail" + j]!= null)&&(item.Fields ["mail" + j] .ToString()!= string.Empty))
{
mId = item ["mail" + j] .ToString();


}
其他
休息;
SendMails(mId,prnum,Iitem,Iitemno,Iitemname);
}
//Response.Write(receivermailid);
//receivermailid = item ["mail1"].ToString();
}
}
}
}
}
}
}
catch(ex ex例外)
{
Response.Write("Error" + ex.Message);
}
}
Hi Sandeep,

I have tried that way..but got the output as..
Answer1Answer1%Answer2Answer1%Answer2%Answer3.I am sending mail in the same code..i have to send 9 mails but sending 27 mails ..so what to do..



Check my code..

protected void Notify(object sender, EventArgs e)
{
SPSite mysite = new SPSite("sitename");
SPWeb MYWEB = mysite.OpenWeb();
SPList Rmslist = MYWEB.Lists["list"];
SPListItemCollection Rmscollection = Rmslist.Items;
string Iitem = null;
string Iitemno = null;
string Iitemname = null;
try
{
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
TextBox box1 = (TextBox)GridView2.Rows[i].Cells[0].FindControl("txtitems");
TextBox box2 = (TextBox)GridView2.Rows[i].Cells[1].FindControl("txtitemno");
TextBox box3 = (TextBox)GridView2.Rows[i].Cells[2].FindControl("txtitemname");
DropDownList ddl1 = (DropDownList)GridView2.Rows[i].Cells[3].FindControl("ddlplants");
DropDownList ddl2 = (DropDownList)GridView2.Rows[i].Cells[4].FindControl("ddlsloc");
TextBox box4 = (TextBox)GridView2.Rows[i].Cells[5].FindControl("txtpr");
//DropDownList ddl3 = (DropDownList)GridView2.Rows[i].Cells[6].FindControl("ddlreqstatus");
DropDownList ddl4 = (DropDownList)GridView2.Rows[i].Cells[6].FindControl("ddlitemstatus");
Iitem += box1.Text;
Iitemno += box2.Text;
Iitemname += box3.Text;
string prnum = box4.Text;
string plant = ddl1.SelectedValue.ToString();
string Slocation = ddl2.SelectedValue.ToString();
string istatus = ddl4.SelectedValue.ToString();
string mId;

if ((prnum != string.Empty) && (istatus == "PR Raised"))
{
foreach (SPListItem item in Rmscollection)
{
if ((plant == item["Plant"].ToString()) && (Slocation == item["Storesloc"].ToString()))
{
for (int j = 1; j < 10; j++)
{
if ((item.Fields["mail" + j] != null) && (item.Fields["mail" + j].ToString() != string.Empty))
{
mId = item["mail" + j].ToString();


}
else
break;
SendMails(mId,prnum,Iitem,Iitemno,Iitemname);
}
//Response.Write(receivermailid);
// receivermailid = item["mail1"].ToString();
}
}
}
}
}
}
}
catch (Exception ex)
{
Response.Write("Error" + ex.Message);
}
}


这篇关于检索Gridview数据为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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