How to show following format in listbox control?

Posted by Sheeba under ASP.NET on 4/29/2011 | Points: 10 | Views : 1786 | Status : [Member] | Replies : 2
Hi

I want to show my listbox control like that


BatchNo : 008 - Partno : 003
BatchNo : 008 - Partno : 004
BatchNo : 008 - Partno : 005
BatchNo : 008 - Partno : 006
BatchNo : 008 - Partno : 007
BatchNo : 008 - Partno : 008

iam using the query like this

c.selectdb(oitem);
oitem.open();
dt = new DataTable();
Ada = new OleDbDataAdapter("SELECT DISTINCT A.BATCHNO,B.PARTNO FROM BATCHCODE A JOIN DETAIL B ON A.BATCH_CODE=B.BATCH_CODE WHERE B.REMARKS='REW.' AND A.BATCH_CODE='"+BatchCode+"'" , oitem.con);
Ada.Fill(dt);
lstRework.DataSource = dt;
lstRework.DataTextField = "BATCHNO";
lstRework.DataValueField = "PARTNO";
lstRework.DataBind();
oitem.close();

how to do...

thanks




Responses

Posted by: Ndebata on: 4/29/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

There are saveral ways to achieve this.

1. Select one more Custum field in data base query which will hold this formatted value.
query will be something like (assuming these columns are strings, else convert them to string before concat)

SELECT DISTINCT A.BATCHNO,B.PARTNO
,'BatchNo : '+A.BATCHNO+' - PartNo : '+B.PARTNO as FVALUE
FROM BATCHCODE A JOIN DETAIL B ON A.BATCH_CODE=B.BATCH_CODE
WHERE B.REMARKS='REW.' AND A.BATCH_CODE='"+BatchCode+"'" , oitem.con


Then use this CustomField as DataTextField
lstRework.DataTextField = "FVALUE";

or
2.
you can simply add a new Column in datatable(dt) in c# and populate formatted values
in your case
After filling the datatable

//Adding a new column
dt.Columns.Add("FVALUE");
//populatingformatted values
foreach (DataRow item in dt.Rows)
{
item["FVALUE"] = String.Format(" BatchNo : {0} - PartNo : {1}", item["BATCHNO"], item["PARTNO"]);
}

lstRework.DataSource = dt;
lstRework.DataTextField = "FVALUE";
lstRework.DataValueField = "PARTNO";
lstRework.DataBind();

Thanks,
Debata

Sheeba, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheeba on: 4/30/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Debata


Thanks a lot

Sheeba, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response