|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
For Each Loop in ASP.NET 2.0I want to create label and checkbox for every member in the database table. How can I do that? I tried: Dim x as integer For Each x In ds.Tables(0).Rows.Count .... code here Next But it didnt work, giving an error: Error 1 Expression is of type 'Integer', which is not a collection type. also how can I code creating a new checkbox and label for every x in the table? Dot Net Daddy napisal(a):
Show quoteHide quote > Hello, Hi,> > I want to create label and checkbox for every member in the database > table. > > How can I do that? > > I tried: > > Dim x as integer > > For Each x In ds.Tables(0).Rows.Count > .... code here > Next > > > But it didnt work, giving an error: > > Error 1 Expression is of type 'Integer', which is not a collection > type. > > also how can I code creating a new checkbox and label for every x > in the table? First of all, you use For Each ... In ... to iterate through a collection of items. In your code x's type should be DataRow and you should interate through collection of rows like that: dim x as DataRow For Each x In ds.Tables(0).Rows .... Next or Dim RowNumber as Integer=ds.Tables(0).Rows.Count for i as integer=1 to RowNumber .... Next Secondly, I don't think creating many Labels and checkboxes is good idea. If you want to show data from dataset it's beter to use GridView. You can have there for example CheckBox field. regards, sweet_dreams Thank you for your help.
I tried to do it with GridView but I couldn't, (I am a newbie) For example, say I want to assign a label the value in the gridview that has been selected. I tried Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged Label1.Text = GridView1.SelectedRow.Cells(0).ToString End Sub when I select a row Label1 is assigned the value: "System.Web.UI.WebControls.DataControlFieldCell" actually I want to assign the value in the selected row to an imageURL. as far as I know GridView should be able to do it. but I couldnt get it done. thanks again for your help... sweet_dreams wrote: Show quoteHide quote > Dot Net Daddy napisal(a): > > Hello, > > > > I want to create label and checkbox for every member in the database > > table. > > > > How can I do that? > > > > I tried: > > > > Dim x as integer > > > > For Each x In ds.Tables(0).Rows.Count > > .... code here > > Next > > > > > > But it didnt work, giving an error: > > > > Error 1 Expression is of type 'Integer', which is not a collection > > type. > > > > also how can I code creating a new checkbox and label for every x > > in the table? > > Hi, > > First of all, you use For Each ... In ... to iterate through a > collection of items. In your code x's type should be DataRow and you > should interate through collection of rows like that: > > dim x as DataRow > > For Each x In ds.Tables(0).Rows > ... > Next > > or > > > Dim RowNumber as Integer=ds.Tables(0).Rows.Count > > for i as integer=1 to RowNumber > ... > Next > > > Secondly, I don't think creating many Labels and checkboxes is good > idea. If you want to show data from dataset it's beter to use GridView. > You can have there for example CheckBox field. > > regards, > sweet_dreams > Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Actualy I don't use ASP but I think that it should be like that:> Object, ByVal e As System.EventArgs) Handles > GridView1.SelectedIndexChanged > Label1.Text = GridView1.SelectedRow.Cells(0).ToString > End Sub > > when I select a row Label1 is assigned the value: > "System.Web.UI.WebControls.DataControlFieldCell" Label1.Text = GridView1.SelectedRow.Cells(0).Value Hope this helps. regards, sweet_dreams There is no control like Cells.Value
thanks anyway for your help sweet_dreams wrote: Show quoteHide quote > > Protected Sub GridView1_SelectedIndexChanged(ByVal sender As > > Object, ByVal e As System.EventArgs) Handles > > GridView1.SelectedIndexChanged > > Label1.Text = GridView1.SelectedRow.Cells(0).ToString > > End Sub > > > > when I select a row Label1 is assigned the value: > > "System.Web.UI.WebControls.DataControlFieldCell" > > Actualy I don't use ASP but I think that it should be like that: > Label1.Text = GridView1.SelectedRow.Cells(0).Value > > Hope this helps. > > regards, > sweet_dreams |
|||||||||||||||||||||||