|
-
May 12th, 2003, 02:14 PM
#1
Thread Starter
Lively Member
Datagrid problem
I'm trying to allow my users to decide what rows from the database they want to see in the datagrid so I have a page where they can set that, but when I try to read those values from the database and try to set the columns to those values I get an error. This is how I am doing it:
Code:
<asp:BoundColumn DataField="<%=Session("sys_header1")%>" SortExpression="<%=Session("sys_header1")%> asc" HeaderText="<%=Session("header1")%>">
<HeaderStyle Font-Size="XX-Small" Font-Names="Microsoft Sans Serif" Font-Bold="True" Wrap="False"></HeaderStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="MS Sans Serif" Wrap="False" HorizontalAlign="Center"></ItemStyle>
</asp:BoundColumn>
But I get this error: Parser Error Message: Literal content ('<asp:BoundColumn DataField="') is not allowed within a 'System.Web.UI.WebControls.DataGridColumnCollection'.
"Find all you need in your mind if you take the time" -DT
-
May 12th, 2003, 02:40 PM
#2
PowerPoster
I think you will have to set it to be a template column. Then put a label control inside it, and use the databinder to databind the column to the labels text property.
-
May 19th, 2003, 01:45 PM
#3
Thread Starter
Lively Member
That worked pretty good thx!!! Any idea how to set the command argument on the link button to a variable though? I cant use the code behind because it doesnt register a withevents event for it. I tried a session variable and that didnt go.
Code:
<asp:TemplateColumn> <HeaderTemplate>
<asp:linkbutton id="Linkbutton1" runat="server" CommandName="sort"> <%#Session("header1")%></asp:linkbutton>
</HeaderTemplate>
<ItemTemplate>
<%#Container.dataItem(Session("sys_header1"))%>
</ItemTemplate>
</asp:TemplateColumn>
"Find all you need in your mind if you take the time" -DT
-
May 19th, 2003, 04:01 PM
#4
PowerPoster
Not sure what you mean...
If you have a link button column, you can use the ItemCommand event of the datagrid itself.
In that event, you can use the argument that is passed in as 'e' to get what was clicked. Example:
If you have a few columns, and one is the primary key column (or a unique column) you can use the e.Item.Cells property to get that value. It will assist you in identifying which rows button was clicked:
PHP Code:
// C#
// Get the unique value of the row of the button the user clicked
TableCell pkCell = e.Item.Cells[0];
string theValueOfTheCell = pkCell.Text;
// Do your processing based on that value here.
VB Code:
'VB.Net
' Get the unique value of the row of the button the user clicked
Dim pkCell As TableCell = e.Item.Cells(0)
Dim theValueOfTheCell As String = pkCell.Text
' Do your processing based on that value here.
-
May 19th, 2003, 05:35 PM
#5
Thread Starter
Lively Member
I guess that would work when dealing with the column contents but this is with the header during the sort command. Basically what I am trying to do is set these properties of the link button in the header of a template row so I can sort. THe reason for the variable is the user can change the default column headers for their search results because our database has about 250 fields in it and I only display 10 of them in the grid. So I have a variable for the literal name of the field and then one for the actual sql field name and I need to pass the name of the field for the sort.
Code:
<asp:linkbutton
id="linkbutton1"
runat="server"
commandname="sort"
commandargument=<%#Session("sys_header1")%>
/>
But it wont let me use that Session("sys_header1") as the commandargument.
"Find all you need in your mind if you take the time" -DT
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|