Results 1 to 3 of 3

Thread: Attributes in Grid- Urgent!

  1. #1

    Thread Starter
    Hyperactive Member jeba's Avatar
    Join Date
    Feb 2000
    Posts
    265

    Attributes in Grid- Urgent!

    Hi there!
    I am using a datagrid with editlinkbutton. So when you edit a row, the values are displayed in textboxes for editing.
    Now I want to run some client side Javascript code on a particular textbox. For ex, when you click on a textbox,
    I want to show a datepicker by passing the next textbox value also.

    Code:
    <asp:TemplateColumn HeaderText="From Date">
         <ItemTemplate>
                   <asp:Label width="80px" ID="lblfdate" runat="server" Text='<%# ConvertDate(DataBinder.Eval(Container.DataItem, "fromdate")) %>' />
        </ItemTemplate>
        <EditItemTemplate>
                 <asp:TextBox width="80px" readonly="true" onclick="ShowDpicker(this,popCal,100,200,'1/Jan/1950',txtTdate.value)"                 runat="server" id="txtfdate" Text='<%# DataBinder.Eval(Container.DataItem, "fromdate") %>' />
        </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="To Date">
             <ItemTemplate>
                 <asp:Label width="80px" ID="lblTdate" readonly="true" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Todate") %>' />
                 </ItemTemplate>
                <EditItemTemplate>
                        <asp:TextBox width="80px" runat="server" id="txtTdate" Text='<%# DataBinder.Eval(Container.DataItem, "Todate") %>' />
                 </EditItemTemplate>
     </asp:TemplateColumn>
    When I click on the 'txtfdate', I am getting a client side error saying, 'txtTdate' is not declared.
    I understand that ASP.NET engine creates names for the controls
    in the datagrid at the runtime and send it to the browser.
    My question is, how do I pass the 'txtTdate' in the 'ShowDatepicker' function of 'txtfdate'?

    Can you please help me?
    Last edited by jeba; Oct 11th, 2002 at 02:57 AM.
    J£ßä

  2. #2
    Hyperactive Member buddu's Avatar
    Join Date
    Jul 2001
    Location
    India
    Posts
    446
    hi Jeba
    try with the following code
    Code:
    Sub dbgrid_Edit(Sender As Object, E As DataGridCommandEventArgs)
            dgrid.EditItemIndex = CInt(E.Item.ItemIndex)
            BindGrid()
            Dim tblRow As TableRow
            tblRow= e.Item.FindControl("txtTdate").Parent.Parent
            tblRow.Attributes.Add("OnClick", "alert('hello');")
    End Sub
    best of luck
    prasad

  3. #3

    Thread Starter
    Hyperactive Member jeba's Avatar
    Join Date
    Feb 2000
    Posts
    265
    Hi Prasad!
    I tried the following code and got an error:

    Code:
    Sub dgrid_Edit(Sender As Object, e As DataGridCommandEventArgs)
            dgrid.EditItemIndex = CInt(e.Item.ItemIndex)
            BindGrid()
            Dim txtfdt As TextBox=CType(e.Item.FindControl("txtfdate"), TextBox)
            lbl.text=txtfdt.text
        End Sub
    Error:

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Can you please tell me why this is happening? I have double checked the names of the controls.
    J£ßä

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width