Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic "id" for checkbox in datagrid 1

Status
Not open for further replies.

JustBarno

Programmer
Jun 21, 2004
46
US
Pardon my ignorance, I'm a .NEWBIE, making the move from classic ASP. I'm populating a datagrid with a list of brokers. I need a checkbox in column one for each broker.

Now normally, I would populate the "id" property of the checkbox control with a dynamic name based off the primary key of our brokers table. However, when I attempt this in .NET, I get the following error.

----------------------------------------------

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: 'brokers<%# DataBinder.Eval(Container.dataitem, "idnum")%>' is not a valid identifier.

Source Error:


Line 27: <asp:TemplateColumn HeaderText="Move">
Line 28: <ItemTemplate>
Line 29: <asp:CheckBox ID='brokers<%# DataBinder.Eval(Container.dataitem, "idnum")%>' Checked='true' runat="server" />
Line 30: </ItemTemplate>
Line 31: </asp:TemplateColumn>
----------------------------------------------

I can assign the same value to the "text" property of the checkbox with no problem, but not the ID. Can someone please point me in the right direction towards a better way to identify which broker checkbox(s) are submitted?

Thanks in advance,

-Justin
 
Hi Justin,

See if this helps
thread855-864198

If you need more, just ask.

Greetings,
Dragonwell
 
I would bind the ID to the DataKeys property. To determine which items are checked cycle through the items in the datagrid, if checked then execute code
Code:
DataGrid.DataSource = [DataTable, DataSet, DataView, Array..]
DataGrid.DataKeyField = [Name of Column]
DataGrid.DataBind()
...

On Some Event
Dim Item as DataGridItem
Dim Chk as CheckBox
Dim Key as Integer

For each Item in DataGrid.Items
  If Item.ItemIndex > -1 Then 'not header or footer
    Chk = CType (DataGrid.FindControl("[]Name of Checkbox"), CheckBox)
    If Chk.Checked then
      'Get ID
      Key = CInt(DataGrid.DataKeys.Item(Item.ItemIndex))
    Else
      'not checked
    End
  End If
Next Item

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top