I have one data grid,with in that datagrid i want to display checkboxes for every row. I will add 2 buttons, button1(text as delete),and one more button2(with text as display).i 'll check some rows and when i press button2 then it has to display only selected rows AND when i click button(delete button) it has to delete the selected rows and display remainig rows.NOTE: use only Asp.net 1.1 with c# as codebehind only

Showing Answers 1 - 3 of 3 Answers

chandan123

  • Nov 22nd, 2006
 

HiI can give logic but not the code.In Grid Command event you have to find the which button is fired. In that case you find the checkbox by using the ID. Then check the checkbox status do the function u want.

  Was this answer useful?  Yes

Sudhanshu Bhatnagar

  • Nov 22nd, 2006
 

Create a new column of Datagrid in this way

<Columns>

         <asp:TemplateColumn>
 <ItemStyle Wrap="False" VerticalAlign="Middle"></ItemStyle>
 <ItemTemplate>
 <asp:checkbox id="chkApSubject" runat="server" OnCheckedChanged="chkApSubject_Click"></asp:checkbox>
</ItemTemplate>

  Was this answer useful?  Yes

Sudhanshu Bhatnagar

  • Nov 22nd, 2006
 

On Aspx file, while creating ur Datagrid ur Checkbox column will be like

<Columns>
<asp:TemplateColumn>
 <ItemStyle Wrap="False" VerticalAlign="Middle"></ItemStyle>
 <ItemTemplate>
 <asp:checkbox id="chk" runat="server" OnCheckedChanged="UR_FUNCTIONNAME"></asp:checkbox>
</ItemTemplate>
.
.
.
</Columns>

On Code behind file write your fuction Name. When ever you Check or Uncheck your check box in Grid this UR_FunctionName will be called during post back. UR_FunctionName:

protected void UR_FunctionName(object sender,EventArgs e)

{

CheckBox chkApproveSA =(CheckBox)sender;

TableCell cell=chkApproveSA.Parent as TableCell;

DataGridItem dbGridItem= cell.Parent as DataGridItem;

if (((CheckBox)dbGridItem.FindControl("chkApSubject")).Checked==true)

{

if(((TextBox)dbGridItem.FindControl("txtDateFrom")).Text =="")

{

((TextBox)dbGridItem.FindControl("txtDateFrom")).Text=DateTime.Now.Date.ToString("MMM/dd/yyyy");

}

// ((RadioButton)dbGridItem.FindControl("optActive")).Checked=true;

}

else

{

if (((TextBox)dbGridItem.FindControl("txtIsNew")).Text=="")

{

((TextBox)dbGridItem.FindControl("txtDateFrom")).Text="";

}

}

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.