Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 8th, 2004, 01:48 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default calling Sub dgData_Update

Hi,

Im trying to call a sub named dgData_Update(E as DataGridCommandEventArgs) from a button click event, but i cant do tat... is there any way to make this done?

I trying to do this bcoz i need to know which row in datagrid is clicked, and then get the ID num of the row :(
let say:

Sub bt1_clicked(sender as object, e as eventargs)
dgData_Update(E)
end sub

sub dgData_Update(E as DataGridCommandEventArgs)
dim strsql as string="Select * From InCStock Where ID="& Ctype(e.Item.Cells(0).Controls(1), Label).text
end sub



In my exact problem, i have 1 datagrid. in my datagrid, i have a link to call the javascript:
<asp:TemplateColumn HeaderText="Delivered22">
   <ItemTemplate>
    <a href="javascript:CreateFile();">Delivered33</a>
   </ItemTemplate>
</asp:TemplateColumn>

in my javascript, i call another event's postback:
  <script language="JavaScript">
        function CreateFile() {
    var fileName = prompt('Type the quantity of this item:','');
    //if the user clicks on OK and if they have entered something
    if ((fileName) && (fileName!="")) {
    //save the filename to the hidden form field 'funcParam'
      document.forms['myForm'].elements['funcParam'].value = fileName;
    //call the postback function with the right ID
      __doPostBack('linkbott','');

    }
  }
    </script>

and here, my linkbott_clicked event:
   Sub linkbott__Click(sender as object, e as EventArgs)
       response.write(funcparam.value)
       response.write("mm")
       dgData_Update(E)
   End Sub

This show me a error something like"special cast not valid"
i need to know which row is clicked.... but i cant call the dgData_Update(E), thus, i can use this statement
"Select * From InCStock Where ID="& Ctype(e.Item.Cells(0).Controls(1), Label).text

I tried to call the dgData_update from my javascript, but no luck...

here is my reference,
http://www.xefteri.com/articles/dec102002/default.aspx
Can any1 pls help here...



Thanks in advance
life's Ng

 
Old October 8th, 2004, 07:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I think you need to get the ID from the datagrid.

intID = dgData.DataKeys( e.Item.ItemIndex )

Then WHERE id = intID

 
Old October 8th, 2004, 07:54 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

Hi stu9820,
Thanks for the reply...
Sorry if i misunderstood ur reply,

intID = dgData.DataKeys( e.Item.ItemIndex )

i use it in my
Sub linkbott__Click(sender as object, e as EventArgs)
dim intID as Integer
intID = dgData.DataKeys( e.Item.ItemIndex )
End Sub

it show me
"Compiler Error Message: BC30456: 'Item' is not a member of 'System.EventArgs'."
This is what i went thru b4 i post my thread...

Regards
life's Ng

 
Old October 11th, 2004, 09:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

It needs to be in sub dgData_Update(E as DataGridCommandEventArgs)

dim strsql as string="Select * From InCStock Where ID="& dgData.DataKeys(e.Item.ItemIndex)

 
Old October 12th, 2004, 10:31 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

yeah, thanks stu9820,

would u try my code here to know whats my exact problem...

<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)
           If Not IsPostBack Then
               Dim dt As DataTable
               Dim dr As DataRow
               Dim i As Integer

    '=========================Create New Table======================
               dt = New DataTable
               dt.Columns.Add(New DataColumn("ID", GetType(Integer)))
               dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
               dt.Columns.Add(New DataColumn("DateTimeValue", GetType(DateTime)))

             For i = 1 To 5
                   dr = dt.NewRow()
                   dr(0) = i
                   dr(1) = "Item " + i.ToString()
                   dr(2) = DateTime.Now.ToShortTimeString
                   'add the row to the datatable
                   dt.Rows.Add(dr)
              Next
               dataGrid1.DataSource = new DataView(dt)
               dataGrid1.DataBind
          End If
       End Sub

       Sub jslink_click(sender as object, e as eventargs)
           response.write(funcparam.value)
           response.write("jslink_click")
        ' dim strsql as string="Select * From InCStock Where ID="& Ctype(e.Item.Cells(0).Controls(1), Label).text
        ' dgData_Delivered(sender,e)
       End Sub

     Sub dgData_ItemDataBound(sender as Object, e as DataGridItemEventArgs)
                    ' check is that dealing footer or header
        If e.Item.ItemType <> ListItemType.Header AND _
              e.Item.ItemType <> ListItemType.Footer then
                    'reference the loc of the Delete ButtonColumn
          Dim deleteButton as LinkButton
          deleteButton= e.Item.Cells(1).Controls(0)
      ' add onclick event handler
          deleteButton.Attributes("onclick") = "javascript:return " & _
          "provalue=prompt('Are you sure item for record ID " & _
           DataBinder.Eval(e.Item.DataItem, "ID") & " arrived?')"
         end if
     end sub

     sub dgData_Delivered(Sender as object, e as DataGridCommandEventArgs)
          response.write(funcparam.value)
          response.write("dgData_Delivered")
          lblString.Text="Select * From InCStock Where ID="& Ctype(e.Item.Cells(0).Controls(1), Label).text
     end sub

</script>
<html>
<head>
    <script language="JavaScript">
    function CreateFile() {
    var fileName = prompt('Type the quantity of this item:','');
    //if the user clicks on OK and if they have entered something
    if ((fileName) && (fileName!="")) {
      document.forms['myForm'].elements['funcParam'].value = fileName;
      //call the postback function with the right ID
     __doPostBack('jslink','');
    }
  }
  </script>
</head>
<body>
    <form id="myForm" runat="server">
        <asp:DataGrid id="dataGrid1" runat="server" BorderColor="black" BorderWidth="1" GridLines="Both" CellPadding="3" CellSpacing="0" HeaderStyle-BackColor="#aaaadd" OnDeleteCommand="dgData_Delivered" ShowFooter="True" OnItemDataBound="dgData_ItemDataBound">
            <Columns>
              <asp:TemplateColumn HeaderText="ID">
                        <ItemTemplate>
                            <asp:Label id="lblId" runat="server" text= '<%# Container.DataItem("ID")%>' />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                <asp:ButtonColumn Text="Arrieved" HeaderText="Arrived?" CommandName="Delete"></asp:ButtonColumn>
                <asp:TemplateColumn HeaderText="MyjavaScript">
                    <ItemTemplate>
                        <a href="javascript:CreateFile();">javatext</a>
                    </ItemTemplate>
                </asp:TemplateColumn>
            </Columns>
        </asp:DataGrid>
        <asp:linkbutton id="jslink" onclick="jslink_click" runat="server"></asp:linkbutton>
        <input id="funcParam" type="hidden" runat="server" />
        <asp:Label id="lblString" runat="server" forecolor="Red"></asp:Label>
    </form>
</body>
</html>

Lets see,
If i use javasript, i can get the value from the pop up window, but cant get the ID of the row clicked;
if i use databound event, i can get the ID of the row clicked, but i cant get the value from pop up window...
I need to get both of this value("ID" of row clicked and User Input from the pop up window) ...So, what should i do..?

Thanks in advance
life's Ng

 
Old October 13th, 2004, 09:34 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

Hi.. Really cant be done ...?

Regards
life's Ng

 
Old October 14th, 2004, 07:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I'm not following what you're trying to do.

Is it giving an error message?

 
Old October 14th, 2004, 10:06 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

Thansk stu9820,
The problem solved.


Regards
life's Ng






Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a sub collatos BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 1 October 3rd, 2008 02:07 PM
Calling activeX from c# jinohere Beginning VB 6 1 August 29th, 2006 10:39 AM
Calling C# from C NoXuS C# 10 May 12th, 2006 10:40 AM
Calling C# DLL from C virajithasarma C# 1 August 17th, 2005 04:01 AM
Calling functions ejmichaud Access VBA 2 July 16th, 2004 10:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.