Link to home
Start Free TrialLog in
Avatar of D Patel
D PatelFlag for India

asked on

Textbox value does not return on gridview linkbutton click

Dear Experts,

Can anybody help me to sort out the issue?

Issue Description : I need to get the textbox entered value in gridview at the time of linkbutton click event.

Design Page :
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="prefLine"
                                                    AllowPaging="True" AllowSorting="True"
                                                    OnPageIndexChanging="GridView1_PageIndexChanging" Width="100%" BackColor="White" BorderColor="#999999" EnableModelValidation="True" GridLines="Vertical">
                                                    <Columns>
                                                        <asp:TemplateField HeaderText="Edit" >
                                                            <ItemTemplate>
                                                                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#String.Format("frmSls.aspx?id={0}&det={1}", HttpUtility.UrlEncode(Eval("nSlsID").ToString()), HttpUtility.UrlEncode(Eval("nSlsDetID").ToString())) %>'
                                                                    Text="Edit" CommandName="select">
                                                                </asp:HyperLink>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                        <asp:BoundField DataField="nSlsDetID" HeaderText="Location">
                                                            <HeaderStyle HorizontalAlign="Center" />
                                                            <ItemStyle HorizontalAlign="Center" />
                                                        </asp:BoundField>
                                                        <asp:TemplateField HeaderText="Position">
                                                            <ItemTemplate>
                                                                <asp:Label ID="lblRowNumber" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="Swap">
                                                            <ItemTemplate>
                                                                <telerik:RadNumericTextBox ID="txtSwapTo" Runat="server" Width="30px" NumberFormat-DecimalDigits="0" />
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderText="">
                                                            <ItemTemplate>
                                                                <asp:LinkButton ID="lnkSwap" CssClass="button" CommandArgument="swap" runat="server" Text="&#8225;" OnClick="ChangePreference" Font-Bold="True" ForeColor="Maroon" Font-Size="Medium">
                                                                    <img src="../images/swap-arrows.gif" height="16" width="16" alt=""/>
                                                                </asp:LinkButton>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                    </Columns>
                                                    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                                                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                                                    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                                                    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" BorderColor="Black" BorderStyle="Solid" VerticalAlign="Middle" />
                                                    <AlternatingRowStyle BackColor="#DCDCDC" />
                                                    <PagerSettings Position="TopAndBottom" />
                                                </asp:GridView>

Open in new window



Code Behind :
Protected Sub ChangePreference(sender As Object, e As EventArgs)
        Dim commandArgument As String = TryCast(sender, LinkButton).CommandArgument

        Dim rowIndex As Double = TryCast(TryCast(sender, LinkButton).NamingContainer, GridViewRow).RowIndex
        Dim rowtxt As GridViewRow = GridView1.Rows(rowIndex)
        Dim locationId As Double = Convert.ToDouble(GridView1.Rows(rowIndex).Cells(1).Text)
        Dim preference As Double = 0 'Convert.ToDouble(GridView1.DataKeys(rowIndex).Value)
        Dim txtswap As RadNumericTextBox = TryCast(rowtxt.FindControl("txtSwapTo"), RadNumericTextBox)
        preference = Val(txtswap.Text)
        Me.UpdatePreference(locationId, preference)

        fillDetaisTable(conn)
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

Open in new window


Here 'preference = Val(txtswap.Text)' I get the value as '0(Zero)'.

Actually I should get textbox entered value.

Can anyone help me please?

Regards,
D Patel
Avatar of HainKurt
HainKurt
Flag of Canada image

just use txtswap.Value not the text...

check this

Getting and Setting Values
http://docs.telerik.com/devtools/aspnet-ajax/controls/input/getting-started/getting-and-setting-values

User generated image
Avatar of D Patel

ASKER

.value also not worked. It returning '0'
put a breakpoint here

Dim txtswap As RadNumericTextBox = TryCast(rowtxt.FindControl("txtSwapTo"), RadNumericTextBox)

add watch this "txtswap" and "rowtxt.FindControl("txtSwapTo")"
then check all properties and values here
you should find what you need here...

also, check the value of Page.IsPostBack
also, what version are you using? people say there was a bug in version 2013.1.40
also, when you add a new textbox here, a regular one like

<telerik:RadNumericTextBox ID="txtSwapTo" Runat="server" Width="30px" NumberFormat-DecimalDigits="0" />
<asp:textbox ID="txtSwapToASP" Runat="server" Width="30px" />

Open in new window


and use

Dim txtswap As RadNumericTextBox = TryCast(rowtxt.FindControl("txtSwapTo"), RadNumericTextBox)
Dim txtswapASP As TextBox = TryCast(rowtxt.FindControl("txtSwapToASP"), TextBox)

Open in new window


do you get correct value from txtswapASP.Text?
Avatar of D Patel

ASKER

Telerik Version is as below :

User generated image
Checked in debugger also. The same values as '0'.

Also, tried with 'Textbox' control. The .Text returns '0' only.
you added a textbox next to RadNumericTextBox
you put some numbers to both
you clicked the linkbutton
and in the ChangePreference event, you get 0 from both control
is that right?
Avatar of D Patel

ASKER

Yes that's correct.

User generated image
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of D Patel

ASKER

Yes, HainKurt,
You are correct that my code clears the value at databind.

I checked it.

I wrote code to databind was at after Not ISPostBack.

Thanks a lot.
Avatar of D Patel

ASKER

Thanks a lot.

Very good Troubleshooter