在C#/ .NET中显示来自数据库(While循环)的内容(Display content from Database (While loop) in C# / .NET)
我对.NET很陌生,不幸的是不得不接管一个前同事的项目。
我的部分代码有一个while循环来循环查询结果...
while (reader.Read()) { pageTitle.Text = reader["title"].ToString(); }
我目前正在使用它从我的数据库中的表中检索页面标题。
我想在SiteMaster文件的
<title></title>
中显示它,但不幸的是现在使用这个方法:
<title><asp:Label ID="pageTitle" runat="server" /></title>
在<title><asp:Label ID="pageTitle" runat="server" /></title>
中给我一个span标记。 我想完全删除并只有标题值。任何人都可以解释做到这一点的最佳方法吗?
感谢您的帮助和耐心。
谢谢
I'm very new to .NET and unfortunately having to take over an ex-colleague's project.
Part of my code has a while loop to loop out query results...
while (reader.Read()) { pageTitle.Text = reader["title"].ToString(); }
I am currently using this to retrieve the Page Title from a Table in my Database.
I want to display this in my
<title></title>
of the SiteMaster file, but unfortunately right now using this method:
<title><asp:Label ID="pageTitle" runat="server" /></title>
is giving me a span tag inside the<title>
. I want to remove the altogether and just have the Title value.Can anyone explain the best way to do this?
Appreciate your help and patience with this.
Thank you
原文:https://stackoverflow.com/questions/6033054
最满意答案
正如您所说的那样,您没有在参数中使用它们(在调用函数时会出现这种情况),您在创建函数时出现的参数中使用它们。
*
和**
运算符在每种情况下都有不同的用途。在定义函数时,它们指定位置参数将放在元组中,并且关键字参数将放在dict中。 是的我只是说了一些论点,但在这种情况下它们适用于参数。
def example(*args, **kwargs): print "args: {0}".format(args) print "kwargs: {0}".format(kwargs) example(1, 2, 'a', foo='bar', bar='foo')
运行时,输出:
args: (1, 2, 'a') kwargs: {'foo': 'bar', 'bar': 'foo'}
当我说我们将它应用于函数定义中的参数时,你是否明白我的意思? 参数是
1, 2, 'a', foo='bar', bar='foo'
。 参数是*args, **kwargs
。现在这里是一个将它们应用于参数的示例。
def example2(a, b, foo=None, bar=None): print "a: {0}, b:{1}, foo:{2}, bar: {3}".format(a, b, foo, bar) args = (1, 2) kwargs = {'foo': 'bar', 'bar': 'foo'} example2(*args, **kwargs)
这输出:
a: 1, b:2, foo:bar, bar: foo
你可以看到,当我们将它们应用于参数时(也就是我们调用函数时),
*
具有扩展列表或元组以填充函数的位置参数的效果,**
具有扩展字典的效果填写函数的关键字参数。 在扩展发生后,您只需要确保总共有足够的参数并且没有太多参数。在最后一个例子中,参数是
*args, **kwargs
,参数是a, b, foo=None, bar=None
As you've stated your question, you aren't using them in the arguments (which occur when you are calling a function), you are using them in the parameters which occur when you are creating a function. The
*
and**
operators serve different purposes in each of those situations.When you are defining a function, they specify that positional arguments will be placed in a tuple and that keyword arguments will be placed in a dict. Yes I did just say arguments, but they are applied to paramaters in this case.
def example(*args, **kwargs): print "args: {0}".format(args) print "kwargs: {0}".format(kwargs) example(1, 2, 'a', foo='bar', bar='foo')
when run, this outputs:
args: (1, 2, 'a') kwargs: {'foo': 'bar', 'bar': 'foo'}
Do you see what I mean when I say that we applied it to the paramaters in the function definition? the arguments are
1, 2, 'a', foo='bar', bar='foo'
. the paramaters are*args, **kwargs
.Now here's an example applying them to arguments.
def example2(a, b, foo=None, bar=None): print "a: {0}, b:{1}, foo:{2}, bar: {3}".format(a, b, foo, bar) args = (1, 2) kwargs = {'foo': 'bar', 'bar': 'foo'} example2(*args, **kwargs)
This outputs:
a: 1, b:2, foo:bar, bar: foo
You can see that when we apply them to arguments (that is when we are calling the function),
*
has the effect of expanding a list or tuple to fill the positional arguments of a function and**
has the effect of expanding a dictionary to fill the keyword arguments of a function. You just need to make sure that there are enough and not too much arguments in total after the expansions have taken place.in the last example, the arguments are
*args, **kwargs
and the parameters area, b, foo=None, bar=None
相关问答
更多-
何时使用*和**作为python函数中的函数参数(When to use * and ** as a function argument in python function)[2023-02-23]
正如您所说的那样,您没有在参数中使用它们(在调用函数时会出现这种情况),您在创建函数时出现的参数中使用它们。 *和**运算符在每种情况下都有不同的用途。 在定义函数时,它们指定位置参数将放在元组中,并且关键字参数将放在dict中。 是的我只是说了一些论点,但在这种情况下它们适用于参数。 def example(*args, **kwargs): print "args: {0}".format(args) print "kwargs: {0}".format(kwargs) example ... -
一个lambda函数(或者更准确地说,一个lambda 表达式 )只是一个你可以在现场定义的函数,就在你需要的地方。 例如, f = lambda x: x * 2 与... 完全一样 def f(x): return x * 2 当我确切地说,我的意思是 - 他们反汇编到相同的字节码。 两者之间的唯一区别在于,第二个示例中定义的名称有一个名称。 Lambda表达式变得有用,因为创建一个不是一个声明,这意味着,正如其他人已经回答的那样,您可以这样做 print iterator(lambda x ...
-
如果绝对不会让用户运行任意Python代码而担心安全风险 ,那么您可以使用eval来创建可调用对象: volume(eval('lambda x: %s' % args.equation), args.a, args.b) If there are absolutely no concerns about security risks from letting the user run arbitrary Python code, then you can use eval to create a cal ...
-
如果您考虑将名称标签附加到对象,而不是将对象填充到命名框中,Python会更有意义。 def lala(a): n = [0, 0 , 0] a = n 这是正在发生的事情。 您正在接收参数(在本例中为列表)并为其指定名称a 。 您正在创建一个新列表并将其命名为n 。 您将给出名为n的附加名称的列表a 。 两个名称a和n都是lala函数的本地名称,因此它们在函数结束时“到期”。 您在函数中创建的列表现在没有名称,Python会丢弃它。 换句话说, a不是可以放入新列表的框。 这是您给出的名 ...
-
你说如果你想从python做到这一点,你会使用inspect模块。 为什么不从C API调用inspect模块? 以下C代码打印了python函数的所有参数。 它也应该是有效的C ++代码。 我不经常使用Python C API,所以请告诉我是否可以改进一些东西。 #include
#include int main(int argc, char* argv[]) { wchar_t* const program = Py_DecodeLocale(arg ... -
import re re.findall(r'\\bibitem\{(.*?)\}', latex_text) # ['item1', 'item2'] import re re.findall(r'\\bibitem\{(.*?)\}', latex_text) # ['item1', 'item2']
-
def override(*override_args, **override_kwargs): def outer(f): def inner(*args, **kwargs): min_args_length = min(len(args), len(override_args)) args = list(args) for i in xrange(min_args_length): ...
-
函数中的参数之类的方法(Method like argument in function)[2023-05-16]
我这样做 def rolling (df, prefix='r', window=3, method='method_name'): for name in df.columns: df[prefix + name] = df[name].rolling(window).__getattribute__(method)() return df I do this def rolling (df, prefix='r', window=3, method='method_na ... -
r“”结构只是告诉Python,字符串中的任何内容都应该被解释为原始数据。 "qw\n" == 'qw\n' r"qw\n" == 'qw\\n'. 使用它是因为“\”路径分隔符也用于换行等。 你可以在参与辩论时跳过它; save_geometry(filefullpath)应该做你期望的。 The r"" construct just tells Python that whatever's in the string should be interpreted as raw data. "qw\n" ...
-
是的,你只需编辑两个语法错误就可以了: 资本'T' True 函数定义def sequence(string, n)后的冒号( def sequence(string, n) 。 更新后的代码如下所示 def perrin(a): if True: #do something here def sequence(string,n): if string == "name": perrin(n) Yes it' ...