我试图在单击它或单击按钮时获取特定gridview行中的值。问题是当我单击该行时没有任何反应,即使我单击按钮也没有。这些行是不可点击的。任何帮助
这是我的 ASPx 页面代码。
<%@ Page Language="C#"Inherits="System.Web.Mvc.ViewPage<MvcApplication3.Models.Order>" %>
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = ViewData["list"];
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckBox x;
foreach (DataGridItem di in GridView1.Rows)
{
x = (CheckBox)di.FindControl("checkBox1");
if (x.Checked == true)
{
Label5.Text = GridView1.SelectedRow.Cells[2].Text;
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Label5.Text = string.Format("YOu selected row{0} with {1} {2}",
GridView1.SelectedIndex + 1,
GridView1.SelectedRow.Cells[0].Text,
GridView1.SelectedRow.Cells[1].Text);
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("ondblclick", "__doPostBack('GridView1','Select$" + e.Row.RowIndex + "');");
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Index</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Tillverkning" InsertVisible="False">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("TillverkningsOrder") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Datum" InsertVisible="False">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("OrderDatum") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Antal" InsertVisible="False">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Kundnamn" InsertVisible="False">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("KundNamn") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>