如何调用函数并将值从aspx传递给aspx.cs [英] How to call a function and pass a value from aspx to aspx.cs
本文介绍了如何调用函数并将值从aspx传递给aspx.cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要调用一个函数并传递一个从DB获取的值。
Gridview如下所示。当Gridview获取第一列的值时,我需要调用一个函数,将获取的值作为参数传递给它并返回一个替换值。
简而言之,我需要传递<%#Eval(LeaveType)%>函数:<%= GetLeaveType()%> 。
如何实现这一目标。请帮帮我。
I need to call a function and pass a value which is fetched from DB.
The Gridview is as follows. When Gridview fetches the value of first column, I need to call a function, pass the fetched value as argument to it and return a replacement value.
In short, I need to pass <%#Eval("LeaveType")%> to the function: <%= GetLeaveType() %> .
How do I achieve this. Please help me out.
<Columns>
<asp:templatefield headertext="LeaveType">
<itemtemplate>
<%#Eval("LeaveType")%>
</itemtemplate>
<edititemtemplate>
<%#Eval("LeaveType")%>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Balance">
<itemtemplate>
<%#Eval("Balance")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="BalanceTxtBox"
text='<%#Eval("Balance")%>'
width="45"
runat="server"/>
</edititemtemplate>
</asp:templatefield>
....
....
<asp:CommandField ShowEditButton="true" HeaderText="Update Record" ItemStyle-Width="30px" />
</Columns>
</asp:GridView>
推荐答案
尝试
'<%#GetLeaveType(Eval("LeaveType"))%>'
你可能需要类似于下面的代码隐藏方法
you may need codebehind method similar to below
protected string GetLeaveType(object leaveType)
{
return "From codebehind";
}
这篇关于如何调用函数并将值从aspx传递给aspx.cs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文