Good day~
I have a problem that cracked my head for a week!
I have a GridView and checkboxes for every each row and a Save button. My GridView contains Serial Number, Type of Asset and Condition. I have 2 checkboxes for "Condition" which are Good or Damage. So, for example, i tick on the checkbox of Good for every each row and click save button. The problem comes!
I DO NOT know how to save the value of checkbox(Good) that i have tick!!!
Can you help me on this? please~~~ Your help is appreciated!!! thank you so much
Loading
Pankaj RawatPosted Apr 24, 2013, 2:04 AM
for the checkbox problems.
and to save Data,
now here i am saving data from label,if you want to save data from textboxes or dropdown,
find the control and then retrieve data from it.
/ ************ /
please inform if you problem gets solved and marked is as "Marked Answer";
xin yiPosted Apr 24, 2013, 9:28 AM
the text in the textbox and the value of checkbox is saved but they are saved in new row.
And the value of checkbox saved is in word of true or false instead of Good or damage.
why?
i left not much time to finish it sir :'(
xin yiPosted Apr 23, 2013, 9:21 AM
nvm, i post it here
Good day sir,
here is my asp coding for the gridview:
Sorry that interrupt you for so many days. I am a beginner for this ASP.NET.
Appreciate that helping me on this.
Pankaj RawatPosted Apr 23, 2013, 1:57 AM
create Checkbox Checked Change event for both the checkboxes.
protected void ChkBox1.CheckedChange(object sender,EventArgs e)
{
checkbox chkbox1=(Checkbox)sender;
GridViewRow row = (GridViewRow)chkbox1.NamingContainer;
int id = row.RowIndex;
checkbox chkbox2=(checkbox )gridview1.Rows[id].FindControl("chkeckbox2ID");
if(chkbox1.checked==true)
chkbox2.checked=false;
}
similarly create the checked change event for second checkbox.
and the problem u are not able to save the details,Please check your code that what exactly are you trying to save.is it a bool value(True or False) or String.
protected void Btn_Save_Click(object sender,EventArgs e)
{
int Total_Rows=gridview1.rows.Count;
for(int i=0;i
{
CheckBox Chk_Good=(CheckBox)gridview1.rows[i].FindControl("chkGood");
CheckBox Chk_Damage=(CheckBox)gridview1.rows[i].FindControl("chkDamage");
bool Is_Condition_Good=Chk_Good.Checked;
bool Is_Condition_Damage=Chk_Damage.Checked;
/* If you want to save Bool value in your database*/
/* just save the Above values "Is_Condition_Good" and "Is_Condition_Damage".*/
/* if you want to save string Values */
string Good_Value=string.empty;
if(Is_Condition_Good)
Good_Value="Good"
string Damage_Value=string.empty;
if(Is_Condition_Damage)
Damage_Value="Damage";
/* Save Record in your Database. */
}
}
if u still find problem you can send me your code(save button click) at [email protected].
i will check it out....
xin yiPosted Apr 22, 2013, 4:00 AM
but whenever i finished tick the checkboxes and press save button, there nothing happen in the database. it is my coding for database wrong?
Secondly, why i can tick 2 checkboxes at the same time? not suppose that only 1 checkbox can be ticked for 1 row?
can help checking on my coding?
here it is:
Pankaj RawatPosted Apr 22, 2013, 12:34 AM
protected void Btn_Save_Click(object sender,EventArgs e)
{
int Total_Rows=gridview1.rows.Count;
for(int i=0;i
{
CheckBox Chk_Good=(CheckBox)gridview1.rows[i].FindControl("chkGood");
CheckBox Chk_Damage=(CheckBox)gridview1.rows[i].FindControl("chkDamage");
bool Is_Condition_Good=Chk_Good.Checked;
bool Is_Condition_Damage=Chk_Damage.Checked;
string Good_Value=string.empty;
if(Is_Condition_Good)
Good_Value="Good"
string Damage_Value=string.empty;
if(Is_Condition_Damage)
Damage_Value="Damage";
/* Save Record in your Database. */
}
}
xin yiPosted Apr 21, 2013, 12:44 PM
According to your coding, then i have wrong coding in asp there as follow:
Then, where i have did wrong in this coding?
How to make 1 ID (Chk_Condition) with 2 checkboxes?
thank u :)
Pankaj RawatPosted Apr 21, 2013, 4:32 AM
suppose your grid Gridview1 has Checkbox Chk_Condition.
on Button click first you find your checkbox control and then checked whether you have selected the value or nor.
protected void Btn_Save_Click(object sender,EventArgs e)
{
int Total_Rows=gridview1.rows.Count;
for(int i=0;i
CheckBox Chk_Condition=(CheckBox)gridview1.rows[i].FindControl("Chk_Condition");
bool condition =Chk_Condition.checked;
/*Here bool condition will have the value.if you checked your checkbox (means Good)the value will be True else False.*/
string Value=string.empty;
if(condition)
Value="Good"
else
Value="Damage";
/* Save Record in your Database. */
}
}