I have two string containing list of ids and respective values.
I want to add them in gridview like we have table with id and proper value.
I have already try this for only "id" below code is for only "id"
string id = "1,2,3,4,5";
ArrayList list = new ArrayList();
list.AddRange(id.Split(new char[] { ',' }));
GridView1.DataSource = list;
GridView1.DataBind();we have one column and five rows in gridview on execution of this code.
but i need two columns having id and values. how can we do this ?
string id = "1,2,3,4,5";
string value = "abc,pqr,xyz,mno,qwe";
ArrayList list = new ArrayList();
list.AddRange(id.Split(new char[] { ',' }));
list.AddRange(value.Split(new char[] { ',' }));
GridView1.DataSource = list;
GridView1.DataBind();this give me single column having 10 rows instead of this i want two columns each i have respective id and values.
Satyapriya NayakPosted Feb 27, 2013, 6:19 AM
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
namespace WebApplication15
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = "1,2,3,4,5";
string value = "abc,pqr,xyz,mno,qwe";
var id1 = id.Split(new char[] { ',' });
var value1 = value.Split(new char[] { ',' });
Dictionary
for (int i = 0; i < id1.Length; i++)
{
dic.Add(id1[i], value1[i]);
}
GridView1.DataSource = dic;
GridView1.DataBind();
}
}
}