Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: how ot use checkbox in datagrid?


Message #1 by "daniel cheng" <daniel.cheng@q...> on Wed, 15 Aug 2001 10:33:58
hi all

i try to use checkbox in datagrid with templat 

but it can't work 

anybody tell me what's it wrong?

below is the source code

thanks



<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SQL" %>

<html><head>

<!--#include file="HRMenu.asp"--></head>

<BODY marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">

<center>

<form id="query_visit" method="post" runat="server">

<table width="100%" border="0">

<TBODY>

<tr>

<td class="SSQT">date</td>

<td class="SSQQ">

<asp:TextBox id=TextBox2 runat="server" ></asp:TextBox>

</td>

<td class="SSQT">name</td>

<td class="SSQQ">

<asp:TextBox id=TextBox1 runat="server" ></asp:TextBox>

</td>

<td class="SSQQ">

<asp:Button id=Button1 runat="server" Text="query" 

onclick="Button1_Click"></asp:Button>

</td>

</tr>

<tr>

<td>

<asp:Button id=Button2 runat="server" Text="save" 

onclick="Button2_Click"></asp:Button>

</td>

</tr>

</form>

</center></TBODY></TABLE>

<p>

<asp:DataGrid id=DataGrid1 runat="server" ForeColor="Black" Width="100%" 

cssclass="SSGR" autogeneratecolumns="False">

<property name="HeaderStyle">

<asp:TableItemStyle CssClass="SSGT">

</asp:TableItemStyle>

</property>

<property name="Columns">

<asp:BoundColumn HeaderText="no" DataField="appnum"></asp:BoundColumn>

<asp:TemplateColumn HeaderText="No" SortField="apvid">

<template name="ItemTemplate">

<input type="checkbox" id="No" runat="server"> 

</template>

</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="yes" SortField="apvid">

<template name="ItemTemplate">

<input type="checkbox" id="Yes" runat="server"> 

</template>

</asp:TemplateColumn>

</property>

</asp:DataGrid></p>



<script language=vb runat=server ID=Script1>

	Sub mydatabind(ByVal strqty As String)

        	Dim cnn As New SQLConnection

("server=workflow4;database=EMI;Uid=sa;Pwd=;")

	        Dim dscmd As New SQLDataSetCommand(strqty, cnn)

        	Dim ds As New DataSet()

	        Dim dv As New DataView()

        	dscmd.FillDataSet(ds, "vith")

	        datagrid1.DataSource = ds.Tables("vith").DefaultView

        	datagrid1.DataBind()

	End Sub



	Sub Button1_Click(sender As Object, e As EventArgs)

		Dim wh As String

	        Dim str As String

        	Dim str1 As String

	        Dim str2 As String

        

		If TEXTBOX1.Text.ToString <> "" Then

                	str1 = " and (emplid like '" & TEXTBOX1.Text.ToString 

& "%' OR connam like '" & TEXTBOX1.Text.ToString & "%')"

		End If

            

		If TEXTBOX2.Text.ToString <> "" Then

                	str2 = "like '" & TEXTBOX2.Text.ToString & "'" 

		Else

                	str2 = "like '%'"

		End If

            

		If Session("wpctgy").ToString = "2" Then

			wh = ""

		ElseIf Session("wpctgy").ToString = "5" Then

			wh = " and depcod = '" + Session

("depcod").ToString + "'"

		Else

			wh = " and depcod = '" + Session

("depcod").ToString + "' and (emplid = '" + Session("name").ToString + "' 

or connam = '" + Session("name").ToString + "')"

		End If

        

		str = "select * from vith where visdtf "

        

		str = str & str2 & str1 & wh

		mydatabind(str)

	End Sub



	Sub Button2_Click(sender As Object, e As EventArgs)

		Dim i As Integer

        

        	For i = 0 To DataGrid1.Items.Count

	            Dim yes As New CheckBox()

        	    yes = DataGrid1.Items(i).FindControl

("Yes")                      

	        Next

	End Sub



</script>

</BODY></html>


  Return to Index