Hi guys,I have 2 questions that I need help with:-
1) How do I get a value from a column of DataTable. Here is the code that I have:-
DataTable tbl = DataCommand.GetSelectedEvent(EventId);
string title = tbl.Columns[0].ToString();
Master.title = configx.titlex + "Latest News ( "+title+" )";
However instead of displaying the value, its displaying the column.
2) this is quite difficult to describe, so pls do let me know if you don't get it ;)
I have a simple blog, in the 1st page, a short description is shown followed by a "More.." button. In the admin form I have 2 fields, 1 for summary & another for full description. The problem that I am having is that how do I hide the "More.." button if there is no content for Full Description?? I am using the Repeater Control. I can't seem to access the hyperlink control when its in the Repeater control. (I really hope that it makes sense!)
Thank you and have a nice day.
For question #1
You're indexing into the Columns collection but you need to index into the Rows collection instead.
Change the line...
string title = tbl.Columns[0].ToString();
to
string title = tbl.Rows[Row Index][Cell Index].ToString();
thanks alcsharp, that did it ;).
If only someone could help me out with question 2 :(
No problem... if you haven't got a solution for #2 yet here's an option.
In your aspx markup, within the itemTemplate, you can conditionally change the visible property based on the value of another field in the datarow that you're binding to.
For example, you can change the visible property of your "More.." button as follows:
<asp:ButtonID="btnMore"Text="More"runat="Server"Visible='<%# Eval("Full Description") == string.Empty? false: true %>'/>
Another option would be use the ItemCreated event of the repeater. You can get a reference to the control using FindControl and cast it to a button or hyperlink as follows:
Button btnMore = (
Button)e.Item.FindControl("btnMore");You can then change it's visibilty after you have the reference to it.
HTH
0 comments:
Post a Comment