I have stripped down my GridView to do some testing with radiobuttons and checkboxes but the event doesn't fire and neither object shows checked.
I have a break set on the "i++;" statement in both of the event handlers, but neither gets there.
What am I missing?
Thanks,
Tom
I have a break set on the "i++;" statement in both of the event handlers, but neither gets there.
What am I missing?
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestGridView.aspx.cs" Inherits="SpearASCWeb.TestGridView" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView visible="true"
border="1"
id="GridView1"
runat="server"
AutoGenerateColumns="False"
CssClass="testsDatagrid"
gridlines="both"
onRowCommand="GridView_RowCommand"
ShowHeaderWhenEmpty="true"
style="margin:0">
<AlternatingRowStyle CssClass="testsDatagridAlternate"/>
<HeaderStyle CssClass="testsDatagridHeader"/>
<Columns>
<asp:TemplateField ItemStyle-Width="10%" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<asp:RadioButton ID="myRadioButton" AutoPostBack="True" OnCheckedChanged="MyRadioButton1_CheckedChanged" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="10%" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<asp:CheckBox ID="myCheckBox" AutoPostBack="True" OnCheckedChanged="MyCheckBox1_CheckedChanged" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using DataLayer;
namespace SpearASCWeb
{
public partial class TestGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet dataSet;
DbObject dbo = new DbObject();
dbo.Parameters.Add(database.SetParameter("@SurveyTestQuestionID", SqlDbType.Int, 50));
dataSet = dbo.GetDataSet("GetSurveyTestAnswers", "TempTable");
if (dataSet.Tables[0].Rows.Count == 0)
{
DataRow dr = dataSet.Tables[0].NewRow();
dataSet.Tables[0].Rows.Add(dr);
}
GridView1.DataSource = dataSet.Tables["tempTable"];
GridView1.DataBind();
}
public void GridView_RowCommand(object s, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridView oGrid = (GridView)s;
if (e.CommandName == "Insert")
{
DbObject myDbObject = new DbObject();
GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);//catching the row in which thhe link button is clicked.
TextBox txtAnswer2 = (TextBox)gvrow.FindControl("txtAnswerFooter");
Label qU = (Label)((GridView)e.CommandSource).Rows[index].FindControl("lblQuestionUniqueFooter");
}
}
public void MyRadioButton1_CheckedChanged(object s, EventArgs e)
{
int i = 10;
i++;
}
public void MyCheckBox1_CheckedChanged(object s, EventArgs e)
{
int i = 10;
i++;
}
}
}
Thanks,
Tom