RadioButtonList&Datagrid

R

rcoco

Hi,
Ihave a datagrid that Insert data in some rows. One column has
RadioButtonList that contains three Items. But When I select one
radiobuton, insert data in other columns and select insert data The
radio button unselects itself. Why would this be happening? here is my
code.

DataTable table = new DataTable();
private DataTable Fill()
{
SqlDataAdapter adapter = new SqlDataAdapter("select * from
dbo.DashBoard", con);
adapter.Fill(table);
return table;
}
private void Bind()
{
dgis.DataSource = table;
dgis.DataBind();
}
private void InsertEmpty()
{
table.Rows.InsertAt(table.NewRow(), 0);
}
private void dgis_ItemCommand(object
source,System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// stop editing
dgis.EditItemIndex = -1;

switch (e.CommandName)
{
case "Insert":
//dgis.EditItemIndex = e.Item.ItemIndex;
break;

case "Update":
System.Web.UI.WebControls.TextBox st=new
System.Web.UI.WebControls.TextBox();
st=(System.Web.UI.WebControls.TextBox)e.Item.Cells[5].FindControl("txtobjach");
System.Web.UI.WebControls.TextBox st1=new
System.Web.UI.WebControls.TextBox();
st1=(System.Web.UI.WebControls.TextBox)e.Item.Cells[4].FindControl("txtobj");
System.Web.UI.WebControls.TextBox st2=new
System.Web.UI.WebControls.TextBox();
st2=(System.Web.UI.WebControls.TextBox)e.Item.Cells[3].Controls[0];
System.Web.UI.WebControls.TextBox st3=new
System.Web.UI.WebControls.TextBox();
st3=(System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0];
System.Web.UI.WebControls.TextBox st4=new
System.Web.UI.WebControls.TextBox();
st4=(System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0];
System.Web.UI.WebControls.RadioButtonList st5=new
System.Web.UI.WebControls.RadioButtonList();
st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[0].FindControl("rblmood");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into DashBoard
(ObjectiveAchieved,Objective) values (@ObjectiveAchieved,
@Objective)";
myCommand.Parameters.Add(new
SqlParameter("@ObjectiveAchieved",SqlDbType.Text));
myCommand.Parameters["@ObjectiveAchieved"].Value=st.Text;
myCommand.Parameters.Add(new
SqlParameter("@Objective",SqlDbType.Text));
myCommand.Parameters["@Objective"].Value=st1.Text;
myCommand.Parameters.Add(new SqlParameter("@Workinghrs",SqlDbType.Char,
45));
myCommand.Parameters["@Workinghrs"].Value=st2.Text;
myCommand.Parameters.Add(new SqlParameter("@Loggedout",SqlDbType.Char,
45));
myCommand.Parameters["@Loggedout"].Value=st3.Text;
myCommand.Parameters.Add(new SqlParameter("@Loggedin",SqlDbType.Char,
45));
myCommand.Parameters["@Loggedin"].Value=st4.Text;
myCommand.Parameters.Add(new
SqlParameter("@MoodToday",SqlDbType.Text));
myCommand.Parameters["@MoodToday"].Value=st5.DataValueField;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgis.EditItemIndex=-1;
BindDataGrid();
break;

case "Cancel":
break;

case "Edit":
// begin editing
dgis.EditItemIndex = e.Item.ItemIndex;
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[6];
ecc.UpdateText = "Insert";
//dgis.EditItemIndex = e.Item.ItemIndex;
break;
}
// fill and bind
Fill();
InsertEmpty();
Bind();
}

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top