小编Ale*_*yev的帖子

如何在Repeater项目中找到已检查的RadioButton?

我在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到对象).

javascript asp.net repeater radio-button

9
推荐指数
2
解决办法
3万
查看次数

如何检查LINQ to SQL连接错误

如何检查Linq.DataContext对象是否填充了数据并且没有出现连接错误?

谢谢.

.net connection error-handling linq-to-sql

9
推荐指数
1
解决办法
8033
查看次数

"DropDownList.SelectedIndex = -1"问题

我只想要一个没有选定项目的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)...我做错了什么?蚂蚁帮助将不胜感激!

asp.net webforms drop-down-menu

8
推荐指数
3
解决办法
7万
查看次数

从int到GUID作为主键移动

我使用几个带有整数主键的引用表.现在我想将更改为GUID,使所有引用保持不变.最简单的方法是什么?

谢谢!

加成

我一般都了解这个过程,所以我需要更详细的建议,例如,如何填写新的GUID列.使用默认值newid()是正确的,但对于现有的行是什么?

sql sql-server database-design

7
推荐指数
2
解决办法
3079
查看次数

有没有办法定义一个List <>的两个元素字符串数组?

我想构建二维数组的字符串,其中一维的长度为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)

不知怎的?

c# arrays generics data-structures

7
推荐指数
2
解决办法
4万
查看次数

在ReadToEnd之后关闭StreamReader

在构造中调用ReadToEnd方法之后是否有可能以某种方式关闭StreamReader:

string s = new StreamReader("filename", Encoding.UTF8).ReadToEnd();
Run Code Online (Sandbox Code Playgroud)

任何具有相同语义的替代优雅结构也将被接受.

.net c# file-io

7
推荐指数
1
解决办法
1万
查看次数

Html.BeginForm使用FormMethod.GET丢失routeValues

我注意到什么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中的错误,有时会被修复吗?

parameters asp.net-mvc get-method

7
推荐指数
1
解决办法
5372
查看次数

用于C#的C++ FQA模拟

我发现C++ FQA Lite非常具有启发性,并希望阅读更多批评.你能推荐一些类似C#的东西吗?

谢谢.

c#

6
推荐指数
1
解决办法
1342
查看次数

如何在WPF应用程序中绘制色轮?

我开始玩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)

不成功,因为渐变仍然是水平的.

另一个想法是我应用渐变后以某种方式弯曲线条.但我找不到适当的变换.

如果没有标准变换,是否可以进行自定义变换?或者我应该按像素绘制色轮?

请问任何想法.

wpf gradient transform color-wheel

6
推荐指数
1
解决办法
3968
查看次数

没有用于Python 3字典的has_key()方法

我读了"Python Cookbook",看看在"寻找两个字典的交叉点"的作品中,作者建议使用这样的单行:

filter(another_dict.has_key, some_dict.keys())
Run Code Online (Sandbox Code Playgroud)

但是由于Python 3字典没有has_key()方法,我应该如何修改建议的代码?我想在__()方法中可能有一些内部__或类似的东西.

请问有什么想法吗?

python python-3.x

5
推荐指数
1
解决办法
9958
查看次数