Click here to Skip to main content
15,923,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
Posted

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!
 
Share this answer
 
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);
}
}
 
Share this answer
 
Comments
Shining Legend 23-Jul-10 0:30am    
Try to debug your code and check if the value it is comparing is correct or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900