D
duancg
Hi,
I wonder if someone could help since I wasn't able to find the answer
through search. I have a simple .aspx page that shows data from a
database table, as a table in UI. Now the data uses 1~12 to represent
months, but I want to show them as Jan/.../Dec. So I thought I could
write a simple function to convert it and call that function in the
Bind expression of DataList. However, I just couldn't find a way to
pass the bind variable value (1~12) into my function. Here is the
code:
.....
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="C:\db2.mdb"
SelectCommand="SELECT [name], [month] FROM [events]" />
<asp
ataList ID="DataList1" runat="server"
DataSourceID="AccessDataSource1">
<ItemTemplate>
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name")
%>'></asp:Label><br />
month:
<asp:Label ID="monthLabel" runat="server" Text='<%#
month_itoa(Eval("month")) %>'></asp:Label><br />
<br />
</ItemTemplate>
</asp
ataList>
.....
CodeFile:
.....
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) { }
public string month_itoa(string i) {
if (i == '1') { return "Jan"; }
if (i == '2') { return "Feb"; }
if (i == '3') { return "Mar"; }
if (i == '4') { return "Apr"; }
if (i == '5') { return "May"; }
if (i == '6') { return "Jun"; }
if (i == '7') { return "Jul"; }
if (i == '8') { return "Aug"; }
if (i == '9') { return "Sep"; }
if (i == '10') { return "Oct"; }
if (i == '11') { return "Nov"; }
if (i == '12') { return "Dec"; }
return "unknow";
}
}
Note, I wanted to pass value of Eval("month") to the function
month_itoa() in the content file, but obviously it didn't work. I
guess there may be a way to get that value within code file without
need to pass the value, but couldn't find any document either. Any
help is appreciated!
Chenggang
I wonder if someone could help since I wasn't able to find the answer
through search. I have a simple .aspx page that shows data from a
database table, as a table in UI. Now the data uses 1~12 to represent
months, but I want to show them as Jan/.../Dec. So I thought I could
write a simple function to convert it and call that function in the
Bind expression of DataList. However, I just couldn't find a way to
pass the bind variable value (1~12) into my function. Here is the
code:
.....
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="C:\db2.mdb"
SelectCommand="SELECT [name], [month] FROM [events]" />
<asp
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
DataSourceID="AccessDataSource1">
<ItemTemplate>
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name")
%>'></asp:Label><br />
month:
<asp:Label ID="monthLabel" runat="server" Text='<%#
month_itoa(Eval("month")) %>'></asp:Label><br />
<br />
</ItemTemplate>
</asp
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
.....
CodeFile:
.....
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) { }
public string month_itoa(string i) {
if (i == '1') { return "Jan"; }
if (i == '2') { return "Feb"; }
if (i == '3') { return "Mar"; }
if (i == '4') { return "Apr"; }
if (i == '5') { return "May"; }
if (i == '6') { return "Jun"; }
if (i == '7') { return "Jul"; }
if (i == '8') { return "Aug"; }
if (i == '9') { return "Sep"; }
if (i == '10') { return "Oct"; }
if (i == '11') { return "Nov"; }
if (i == '12') { return "Dec"; }
return "unknow";
}
}
Note, I wanted to pass value of Eval("month") to the function
month_itoa() in the content file, but obviously it didn't work. I
guess there may be a way to get that value within code file without
need to pass the value, but couldn't find any document either. Any
help is appreciated!
Chenggang