G
Guest
Hi,
I read http://www.dotnetjohn.com/articles/articleid57.aspx and I need the C# version.
Here is the VB code
Sub ChangeWhereClause(Sender As System.Object, e As System.EventArgs)
Dim strWhereClause As String = ""
For Each li in lsbEmployee.Items
If li.Selected Then
strWhereClause &= "EmployeeID=" & li.Value & " Or "
End If
Next
If strWhereClause.Length > 0 Then
dtgEmployee.Visible = True
'Chop off last " Or "
strWhereClause = Left(strWhereClause, strWhereClause.Length() - 4)
strWhereClause = "WHERE " & strWhereClause
1. How can I convert the foreach loop? I tried foreach(li in lsbEmployee.Items), but "in" has a red underline to show error in cs file.
2. How can I convert the 'Chop off last " Or " ?
3. How can I convert the Left(strWhereClause, strWhereClause.Length() - 4) ?
Array question:
I have a string variable
protected string SelectedDeptIDs
{
get
{
return ViewState["SelectedDeptIDs"] == null? ""string)ViewState["SelectedDeptIDs"];
}
set
{
ViewState["SelectedDeptIDs"] = value;
}
}
private void InitializeComponent()
{
this.listDept.SelectedIndexChanged += new System.EventHandler(this.listDept_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void listDept_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.SelectedDeptIDs = this.listDept.SelectedItem.Value;
ListStaffDataBind();
}
Since there are many this.listDept.SelectedItem.Value in a listbox, how can I save their values to SelectedDeptIDs? Should I use array?
After setting it, how can I retrieve the individual SelectedDeptIDs? How can I split them?
Thanks
I read http://www.dotnetjohn.com/articles/articleid57.aspx and I need the C# version.
Here is the VB code
Sub ChangeWhereClause(Sender As System.Object, e As System.EventArgs)
Dim strWhereClause As String = ""
For Each li in lsbEmployee.Items
If li.Selected Then
strWhereClause &= "EmployeeID=" & li.Value & " Or "
End If
Next
If strWhereClause.Length > 0 Then
dtgEmployee.Visible = True
'Chop off last " Or "
strWhereClause = Left(strWhereClause, strWhereClause.Length() - 4)
strWhereClause = "WHERE " & strWhereClause
1. How can I convert the foreach loop? I tried foreach(li in lsbEmployee.Items), but "in" has a red underline to show error in cs file.
2. How can I convert the 'Chop off last " Or " ?
3. How can I convert the Left(strWhereClause, strWhereClause.Length() - 4) ?
Array question:
I have a string variable
protected string SelectedDeptIDs
{
get
{
return ViewState["SelectedDeptIDs"] == null? ""string)ViewState["SelectedDeptIDs"];
}
set
{
ViewState["SelectedDeptIDs"] = value;
}
}
private void InitializeComponent()
{
this.listDept.SelectedIndexChanged += new System.EventHandler(this.listDept_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void listDept_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.SelectedDeptIDs = this.listDept.SelectedItem.Value;
ListStaffDataBind();
}
Since there are many this.listDept.SelectedItem.Value in a listbox, how can I save their values to SelectedDeptIDs? Should I use array?
After setting it, how can I retrieve the individual SelectedDeptIDs? How can I split them?
Thanks