Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 updating datagrid col based on Check Box selection

Author  Topic 

kris22
Starting Member

35 Posts

Posted - 2008-11-20 : 15:12:33
Hi,

I am using VS.NET2003/VB.NET/ASP.NET. I added a template column for check box with in the datagrid. how do i update the datagrid column based on row checked. can you guys help me with some code examples? appreciate your help
Thx

ramsesiitr
Starting Member

22 Posts

Posted - 2008-11-25 : 06:53:51
Hi,

On source code of your asp page, find the checkbox and write this as a property

CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'


This will give you the index of the checkbox's row which was checked. I dont know any VB coding but I can give you some code in C#, maybe you can figure it out.


protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
int index=Convert.ToInt32(e.CommandArgument);//we got the index of the row

//now you can reach the columns of the row here

}
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-11-25 : 07:17:34
www.gridviewguy.com has 1st class examples
Go to Top of Page

kris22
Starting Member

35 Posts

Posted - 2008-12-03 : 17:38:08
Hi,

I tried with the below code for deleting the row based on the check box selection, but it doesn't work. can you guys help me with code? i am using vs.net 2003/vb.net/asp.net
Thx

Dim Chk1 As System.Web.UI.WebControls.CheckBox
Dim chkDel As DataGridItem
Dim del_empID As Integer
For Each chkDel In dgspoto.Items
Chk1 = chkDel.FindControl("checkbox")
If Chk1.Checked Then
'trying to get the primary key of the row to delete
del_empID = Convert.ToInt32(dgspoto.DataKeys(chkDel.ItemIndex).ToString())
sql = "delete from tblveen where tblveen.id = (" & del_empID & ")"
dbfunctions.RunSQLQuery(CONNECTIONSTRING, sql)


End If
Next
Go to Top of Page
   

- Advertisement -