Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: How Get The Value ?


Message #1 by "Nick" <nick@g...> on Thu, 11 Jul 2002 14:13:58 +0700
This is a multi-part message in MIME format.

------=_NextPart_000_016C_01C228E5.32E44E00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hai.. I'm new in here, please help me how to get the value when i click 
the Addbutton and Editbutton, why when i click on it there's no value 
and the script was error ?? I use my own database and use my own tabel, 
so to runing this program need to change the database ... is that my 
code error or what ?? PLEASE HELP ASAP ?? 


<%@ Page Language=3D"VB" debug=3Dtrue%>
<%@ Import Namespace=3D"System" %>
<%@ Import Namespace=3D"System.Configuration" %>
<%@ Import Namespace=3D"System.Data" %>
<%@ Import Namespace=3D"System.Data.SqlClient" %>
<%@ Import Namespace=3D"System.Web.UI.WebControls.DataGrid" %>

<script language=3D"VB" runat=3D"server">
    Sub Page_Load(sender As Object, e As EventArgs)
        If Not Page.IsPostBack Then
 BindGrid()
        End If
    End Sub

    Sub MyDataGrid_Page(sender As Object, e As 
DataGridPageChangedEventArgs)
 dim startIndex as Integer
        startIndex =3D DG_CheckBox.CurrentPageIndex * 
DG_CheckBox.PageSize
 DG_CheckBox.CurrentPageIndex =3D e.NewPageIndex

        BindGrid
    End Sub

    private Sub BindGrid()
     Dim myConnection As SqlConnection =3D New 
SqlConnection(ConfigurationSettings.AppSettings("PubsDSN"))

  dim ds as DataSet =3D new DataSet()
  dim adapter as SqlDataAdapter =3D new SqlDataAdapter("spvnews", 
myConnection)
  adapter.Fill(ds,"TBNews")

   DG_CheckBox.DataSource=3Dds.Tables("TBNews").DefaultView
   DG_CheckBox.DataBind()
  
  
    End Sub


    Sub PagerButtonClick(sender As Object, e As EventArgs)
        'used by external paging UI
        Dim arg As string =3D sender.CommandArgument

        Select arg
            Case "next":
                If (DG_CheckBox.CurrentPageIndex < 
(DG_CheckBox.PageCount - 1)) Then
                    DG_CheckBox.CurrentPageIndex +=3D 1
                End If   
            Case "prev":
                If (DG_CheckBox.CurrentPageIndex > 0) Then
                    DG_CheckBox.CurrentPageIndex -=3D 1
                End If   
            Case "last":
                DG_CheckBox.CurrentPageIndex =3D (DG_CheckBox.PageCount 
- 1)
            Case Else:
                'page number
                 DG_CheckBox.CurrentPageIndex =3D 
System.Convert.ToInt32(arg)
        End Select
        BindGrid
    End Sub


    Sub btnSelect_OnClick(ByVal sender As Object, ByVal e As EventArgs)
        Dim myDataGridItem As DataGridItem
        Dim chkSelected As System.Web.UI.WebControls.CheckBox
        Dim strStoreName As String
        Dim strStoreID As String

        lblStatus.Text =3D "<br>You selected the Following 
items:<br><br>"
        For Each myDataGridItem In DG_CheckBox.Items
   chkSelected =3D myDataGridItem.FindControl("chkSelection")
   If chkSelected.Checked Then
       strStoreName =3D 
CType(myDataGridItem.FindControl("lblStoreName"), Label).Text
       strStoreID =3D CType(myDataGridItem.FindControl("hdnStoreID"), 
Label).Text
       lblStatus.Text +=3D "The store name is <b>" & strStoreName & 
"</b>"
       lblStatus.Text +=3D " and the StoreID is <b>" & strStoreID & 
"</b><br>"
 End If
        Next
    End Sub  

    Sub DataGrid_Edit(Source As Object, E As DataGridCommandEventArgs)
   
    DG_CheckBox.EditItemIndex=3DE.Item.itemindex
    If e.CommandSource.CommandName =3D "EditItem" Then  
  response.redirect("abcd.html?test=3D"&E.Item.Cells(1).Text)
  Else
  response.redirect("abcd.html?delete=3D"&DG_CheckBox.EditItemIndex)
  End if

       BindGrid
 End Sub
     
 </script>
<html>
<head></head>
<body>
<blockquote>
<form runat=3D"server">
      <ASP:DataGrid id=3D"DG_CheckBox" runat=3D"server"
        AllowPaging=3D"True"
        PageSize=3D"5"
        PageCount=3D"1"
        PagerStyle-Mode=3D"NumericPages"
        PagerStyle-HorizontalAlign=3D"Right"
        OnPageIndexChanged=3D"MyDataGrid_Page"
  OnItemCommand=3D"DataGrid_Edit"
        BorderColor=3D"black"
        BorderWidth=3D"1"
        GridLines=3D"Both"
        CellPadding=3D"3"
        CellSpacing=3D"0"
        Font-Name=3D"Verdana"
        Font-Size=3D"8pt"
        HeaderStyle-BackColor=3D"#aaaadd"
        AlternatingItemStyle-BackColor=3D"#eeeeee"
        AutoGenerateColumns=3D"False">

<Columns>
  <asp:TemplateColumn HeaderStyle-HorizontalAlign=3DCenter  
HeaderText=3D"X">
              <ItemTemplate>
                 <asp:LinkButton ID=3DAddButton Text=3D"Edit" 
CommandName=3D"EditItem" ForeColor=3D"blue" runat=3D"server" />&nbsp;
                 <asp:LinkButton ID=3DRemoveButton Text=3D"Remove" 
CommandName=3D"Remove" ForeColor=3D"blue" runat=3D"server" />

                 <asp:Checkbox ID=3D"chkSelection"
                              Runat=3Dserver />
               <asp:Label ID=3D"hdnStoreID"
  Visible=3D"False"
  Text=3D'<%# DataBinder.Eval(Container.DataItem, "NewsID") %>'
  Runat=3Dserver />
              </ItemTemplate>
  </asp:TemplateColumn>    

  <asp:TemplateColumn HeaderText=3D"Title">
              <ItemTemplate>
               <asp:Label ID=3D"lblStoreName"
    Text=3D'<%# DataBinder.Eval(Container.DataItem, "Title") %>'
    Runat=3Dserver />          
              </ItemTemplate>
  </asp:TemplateColumn>
            
  <asp:TemplateColumn HeaderText=3D"Create Date">
              <ItemTemplate>
               <asp:Label ID=3D"lblStoreAddress"
    Text=3D'<%# DataBinder.Eval(Container.DataItem, "Createdate") %>'
    Runat=3Dserver />          
              </ItemTemplate>
  </asp:TemplateColumn>
               
 </Columns>   
 </asp:DataGrid>

 <input type=3D"button"
              id=3D"btnSelect"
              OnServerClick=3D"btnSelect_OnClick"
              value=3D"Select my Stores"
              runat=3D"server">
             
 <asp:Label ID=3D"lblStatus"
               Font-Name=3D"verdana"
               Font-Size=3D"12px"
               ForeColor=3D"#ff0000"
               Runat=3Dserver />
<asp:Label ID=3D"lab"
               Font-Name=3D"verdana"
               Font-Size=3D"12px"
               ForeColor=3D"#ff0000"
               Runat=3Dserver />              
      <p>
     
</form>
</blockquote>
</body>
</html>




  Return to Index