0
Answer

Images in datagrid!

Hi,
I have a datagrid that Inserts data into sql datbase, and amongest there is a column that has a radiobuttonlist, the radiobuttonlist contains two radiobuttons one with Good Mood and the otherone with bad moods. In the column I placed two images where one shows a happy face and the other one a sad face and I want when a user selects radiobutton Good Mood the image with a happy face is inserted. but I'm having a problem when I select radiobutton Good Mood I only get Good Mood inserted but not the image. How should I do this? here is the code I'm using:

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":

break;

case "Update":

System.Web.UI.WebControls.TextBox st=new System.Web.UI.WebControls.TextBox();

st=(System.Web.UI.WebControls.TextBox)e.Item.Cells[6].FindControl("txtobjach");

System.Web.UI.WebControls.TextBox st1=new System.Web.UI.WebControls.TextBox();

st1=(System.Web.UI.WebControls.TextBox)e.Item.Cells[5].FindControl("txtobj");

System.Web.UI.WebControls.TextBox st2=new System.Web.UI.WebControls.TextBox();

st2=(System.Web.UI.WebControls.TextBox)e.Item.Cells[4].Controls[0];

System.Web.UI.WebControls.TextBox st3=new System.Web.UI.WebControls.TextBox();

st3=(System.Web.UI.WebControls.TextBox)e.Item.Cells[3].Controls[0];

System.Web.UI.WebControls.TextBox st4=new System.Web.UI.WebControls.TextBox();

st4=(System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0];

System.Web.UI.WebControls.RadioButtonList st5=new System.Web.UI.WebControls.RadioButtonList();

st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[1].FindControl("rblmood");

System.Web.UI.WebControls.Image imgDaily = new System.Web.UI.WebControls.Image();

imgDaily=(System.Web.UI.WebControls.Image)e.Item.Cells[1].FindControl("imgm");

System.Web.UI.WebControls.TextBox st6=new System.Web.UI.WebControls.TextBox();

st6=(System.Web.UI.WebControls.TextBox)e.Item.Cells[0].FindControl("txtname");

SqlCommand myCommand=new SqlCommand();

myCommand.Connection=con;

myCommand.CommandText="insert into DashBoard (ObjectiveAchieved,Objective,MoodToday,Name) values (@ObjectiveAchieved, @Objective,@MoodToday,@Name)";

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.SelectedValue;
myCommand.Parameters.Add(new SqlParameter("@Name",SqlDbType.Text));

myCommand.Parameters["@Name"].Value=st6.Text;

if(e.Item.Cells[1].Equals("Good Mood"))

{

imgDaily.ImageUrl = "IS_dashboard/Moods/laughing.gif";

}

else

{

imgDaily.ImageUrl = "IS_dashboard/Moods/sad.gif";

}

con.Open();

myCommand.ExecuteNonQuery();

con.Close();

dgis.EditItemIndex=-1;

BindDataGrid();

break;
case "Cancel":
break;
case "Edit":
dgis.EditItemIndex = e.Item.ItemIndex;
EditCommandColumn ecc = (EditCommandColumn) dgis.Columns[7];
ecc.UpdateText = "Insert";
break;
}
Fill();
InsertEmpty();
Bind();
}
protected void rblmood_SelectedIndexChanged(object sender, System.EventArgs e)
{
RadioButtonList rbl = (RadioButtonList)sender;
Control parent = rbl.Parent;
while(!(parent is System.Web.UI.WebControls.DataGridItem))
{
parent = parent.Parent;
}

}
protected int SetState(object st)
{
string state = st.ToString();

if(state.Equals("True"))
{
return 0;
}
else
{
return 1;
}
}

Thanks.