我在ASPX页面上有一个Repeater控件,定义如下:
<asp:Repeater ID="answerVariantRepeater" runat="server"
onitemdatabound="answerVariantRepeater_ItemDataBound">
<ItemTemplate>
<asp:RadioButton ID="answerVariantRadioButton" runat="server"
GroupName="answerVariants"
Text='<%# DataBinder.Eval(Container.DataItem, "Text")%>'"/>
</ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
要允许只选择一个时间我已经用了一招形式单选按钮这篇文章.
但现在提交表单时,我想确定选中了哪个单选按钮.
我能做到这一点:
RadioButton checkedButton = null;
foreach (RepeaterItem item in answerVariantRepeater.Items)
{
RadioButton control=(RadioButton)item.FindControl("answerVariantRadioButton");
if (control.Checked)
{
checkedButton = control;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
但希望它可以以某种方式简化(可能通过LINQ到对象).
如何检查Linq.DataContext对象是否填充了数据并且没有出现连接错误?
谢谢.
我只想要一个没有选定项目的ASP.NET DropDownList.到目前为止,将SelectedIndex设置为-1无济于事.我正在使用带有AJAX的Framework 3.5,即此DropDownList位于UpdatePanel中.这是我在做的事情:
protected void Page_Load (object sender, EventArgs e)
{
this.myDropDownList.SelectedIndex = -1;
this.myDropDownList.ClearSelection();
this.myDropDownList.Items.Add("Item1");
this.myDropDownList.Items.Add("Item2");
}
Run Code Online (Sandbox Code Playgroud)
我在DropDown中添加一个元素的那一刻,它的SelectedIndex更改为0并且不能再设置为-1(我在添加项目后尝试调用SelectedIndex)...我做错了什么?蚂蚁帮助将不胜感激!
我使用几个带有整数主键的引用表.现在我想将更改为GUID,使所有引用保持不变.最简单的方法是什么?
谢谢!
加成
我一般都了解这个过程,所以我需要更详细的建议,例如,如何填写新的GUID列.使用默认值newid()是正确的,但对于现有的行是什么?
我想构建二维数组的字符串,其中一维的长度为2.与此类似
string[,] array = new string[,]
{
{"a", "b"},
{"c", "d"},
{"e", "f"},
{"g", "h"}
}
Run Code Online (Sandbox Code Playgroud)
干
List<string[]> list = new List<string[]>();
list.Add(new string[2] {"a", "b"});
list.Add(new string[2] {"c", "d"});
list.Add(new string[2] {"e", "f"});
list.Add(new string[2] {"g", "h"});
list.ToArray();
Run Code Online (Sandbox Code Playgroud)
给我
string[][]
Run Code Online (Sandbox Code Playgroud)
但不是
string[,]
Run Code Online (Sandbox Code Playgroud)
阵列.
只是好奇,是否有动态构建的技巧
string[,]
Run Code Online (Sandbox Code Playgroud)
不知怎的?
在构造中调用ReadToEnd方法之后是否有可能以某种方式关闭StreamReader:
string s = new StreamReader("filename", Encoding.UTF8).ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
任何具有相同语义的替代优雅结构也将被接受.
我注意到什么Html.BeginForm()方法编码提供routeValues到行动 FORM标签的属性.这适用于POST方法.但是如果方法是GET,则操作URL中的所有参数都被浏览器剥离(在IE8和Firefox 3.0.7上测试).
例如,这个代码在视图中
<%
using (Html.BeginForm("TestAction", "TestController", new { test = 123 },
FormMethod.Get))
{
Response.Write("<input type='submit'>");
};
%>
Run Code Online (Sandbox Code Playgroud)
给出了这样的HTML
<form action="/TestController/TestAction?test=123" method="get">
<input type='submit'>
</form>
Run Code Online (Sandbox Code Playgroud)
但提交表单后的URL变为/ TestController/TestAction而不是/ TestController/TestAction?test = 123(参数丢失).
现在我使用Html.Hidden()调用而不是routeValues参数,但我感兴趣的还有另一种解决方法吗?它应该被视为MVC中的错误,有时会被修复吗?
我开始玩WPF并希望在表格上绘制色轮.
起初我尝试在ArcSegment上使用LinearGradientBrush,如下所示:
<Path StrokeThickness="35" Height="150" Width="150">
<Path.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="Red" Offset="0.15" />
<GradientStop Color="Orange" Offset="0.2" />
<GradientStop Color="Yellow" Offset="0.35" />
<GradientStop Color="Green" Offset="0.5" />
<GradientStop Color="Blue" Offset="0.65" />
<GradientStop Color="Indigo" Offset="0.75" />
<GradientStop Color="Violet" Offset="0.9" />
</LinearGradientBrush>
</Path.Stroke>
<Path.Data>
<PathGeometry >
<PathFigure IsClosed="True" StartPoint="25,70">
<ArcSegment Point="25,71" IsLargeArc="True"
Size="50,50" SweepDirection="Clockwise" />
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
Run Code Online (Sandbox Code Playgroud)
不成功,因为渐变仍然是水平的.
另一个想法是我应用渐变后以某种方式弯曲线条.但我找不到适当的变换.
如果没有标准变换,是否可以进行自定义变换?或者我应该按像素绘制色轮?
请问任何想法.
我读了"Python Cookbook",看看在"寻找两个字典的交叉点"的作品中,作者建议使用这样的单行:
filter(another_dict.has_key, some_dict.keys())
Run Code Online (Sandbox Code Playgroud)
但是由于Python 3字典没有has_key()方法,我应该如何修改建议的代码?我想在__()方法中可能有一些内部__或类似的东西.
请问有什么想法吗?
c# ×3
.net ×2
asp.net ×2
arrays ×1
asp.net-mvc ×1
color-wheel ×1
connection ×1
file-io ×1
generics ×1
get-method ×1
gradient ×1
javascript ×1
linq-to-sql ×1
parameters ×1
python ×1
python-3.x ×1
radio-button ×1
repeater ×1
sql ×1
sql-server ×1
transform ×1
webforms ×1
wpf ×1