I have created a listbox in which i want to access all fields from datasource.
if (dt.Rows.Count > 0)
{
ListBox1.DataSource = dt;
ListBox1.DataTextField = "infavor"; // the items to be displayed in the list items
ListBox1.DataValueField = "infavor"+"-"+"APP_id"; // the id of the items displayed
ListBox1.DataBind();
}
In this i want to bind infavor to multiple columns in datasource ...In the above code i tried to concatinate but that does not work..
Other thing i want to know is that i have created databound field voucher_no which i want initialize with 000001 and every time i create a new form it gets incremented and if a form is deleted it gets +1 value than last record.
Please help!!
Use for each.
ListBox1.Items.Clear();
foreach (DataRow dr in dt.Rows)
{
string value = dr["infavor"].ToString() + " - " + dr["APP_id"].ToString();
ListItem li = new ListItem(dr["infavor"].ToString(), value);
ListBox1.Items.Add(li);
}
Hope this helps...
Don't bind the ListBox1 to Datasource. Add the items manualy. ListBox1.Items.Add(dr["infavor"].ToString() + "-" + dr["APP_id"].ToString()) ;
Or change your select command. SELECT (infavor + '-' + APP_id) as listboxfield
Thank you oned... Now please also tell that if i move items from 1 listbox to other than how can i save them to my database by using the app id....
In My list box i get name-app id..
like abc-101
is it possible to show only the app id in 2nd listbox and not the name...
The below code will extract appid
string s = "abc-101";
int lastIndex = s.LastIndexOf("-");
int id = int.Parse(s.Substring(lastIndex + 1, s.Length - lastIndex - 1));
how would that work if iam bouding listbox1 items to database.
when i click the button i want only the app_id to be shown in 2nd listbox and when i click remove button both app_id and infavor to be added back to the 1st listbox.
What about auto incrementing voucher_no?
SELECT app_id, (infavor + '-' + APP_id) as listboxfield... set datavaluefield="app_id" DataTextField="listboxfield"
i am using the following code for update
update a_settle set tds_voucher_no = '"+voucher_no.Text+"' where App_id='"+ListBox2.Items+"'",myconnection2)
but that is not updating the field.
In listbox2 i have items such as abc - 101
where abc is infavor and 101 is app id
"update a_settle set tds_voucher_no = '"+voucher_no.Text+"' where
App_id='"+ListBox2.SelectecValue.ToString()+"'",myconnection2)
Even this is not working....
below is my select string code..
try
{
myconnection2.Open();
string sqlStatement = "SELECT (infavor+' - '+App_id) as App_id FROM a_settle";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, myconnection2);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
ListBox1.DataSource = dt;
ListBox1.DataTextField = "App_id"; // the items to be displayed in the list items
ListBox1.DataValueField = "App_id";// the id of the items displayed
ListBox1.DataBind();
}
}
PLEASE ALSO SOLVE MY AUTOINCREMENT QUERY
akkibansal
PLEASE ALSO SOLVE MY AUTOINCREMENT QUERY
Use ID (int), set isidentity = true, increament by 1
[ID] [int] IDENTITY(1,1)
You can format ID to 0000001 using SQL Query or using DataFormatString in ASPX page.
SELECT RIGHT('000000' + CAST(ID AS Varchar),6) as FormatedID
or
DataField="ID" DataFormatString="{0:000000}"
or
Text='<%# Eval("ID","{0:000000}") %>'
沒有留言:
張貼留言