Click here to Skip to main content
16,001,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all respected Engineers..

I have a GridView which is shown in Jquery Ui Dialog. I want to update the datatable when update button is clicked. But when I am trying to access the controls in grid, its value is empty for textboxes and selectedindex is 0 for dropdownlist.

Alternatively when I am displaying the gridview in normal webform, it works fine.

Please throw some light on this. I am stuck up on this since last a week.

Here is my Javascript



JavaScript
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"/>
    <%--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>--%>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <link rel="Stylesheet" href="css/GridStyle.css" />
    <style type="text/css">
        .ui-dialog .ui-state-error { padding: .3em; }
        .validateTips { border: 1px solid transparent; padding: 0.3em; }
    </style>

    <script type="text/javascript" language="javascript">

        $(function () {
            $("#<%= pmDialog.ClientID %>").dialog({
                autoOpen: false,
                hide: "clip",
                show: "clip",
                height: 600,
                width: 600,
                modal: true,
                buttons: {
                    "Submit": function () {
                        var ShowAlert = true;
                        var IsValid = true;
                        $("#<%=gvUnmappedProducts.ClientID%> tr:has(td)").each(function () {
                            var product = $(this).find("td:last").find("[id$='ddlProducts']"); //$("[id$='ddlProducts']"); 
                            if (product.val() <= 0) {
                                if (ShowAlert) {
                                    ShowAlert = false;
                                    alert("Please Map All the Products.");
                                }
                                product.addClass("ui-state-error");
                                IsValid = false;
                                //return false;
                            }
                        });

                        if (IsValid) {

                            $("#<%=gvUnmappedProducts.ClientID%> tr:has(td)").each(function () {
                                var product = $(this).find("td:last").find("[id$='ddlProducts']"); //$("[id$='ddlProducts']"); 
                                var lblProduct = $(this).find("td:last").find("[id$='lblProductId']").attr("id"); 
                                //$("#" + lblProduct).attr("Text", product.val());
                            });


                            $(this).dialog("close");

                    "Cancel": function () {
                        $(this).dialog("close");
                    }
                }

            });
        });
        

        function OpenProductMapping() {
            $("#<%= pmDialog.ClientID %>").dialog("open");
            return false;
        }
</script>


Aspx:
ASP.NET
<div id="pmDialog"  runat="server" title="Product Mapping Form" >
    <p class="validateTips"> </p>
    <table>
        <tr>
            <td>
                <beg:BulkEditGridView ID="gvUnmappedProducts"  runat="server" AutoGenerateColumns="false" Width="100%"
                    AllowPaging="true" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                    OnPageIndexChanging="gvUnmappedProducts_PageIndexChanging" BulkEdit="True" 
                    OnRowDataBound="gvUnmappedProducts_RowDataBound"  önRowUpdating="gvUnmappedProducts_RowUpdating" >
                    <Columns>
                        <%--<asp:BoundField DataField="NewProductID" HeaderText="ID" />
                        <asp:BoundField DataField="NewProductName" HeaderText="Product Name" />--%>
                            
                            
                        <asp:TemplateField HeaderText="ID" HeaderStyle-Width="20px">
                            <ItemTemplate>
                                <asp:Label id="lblSheetProductID" runat="server" Text='<%#Bind("NewProductID") %>' ></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Textbox id="txtSheetProductID" runat="server" Width="20px" Text='<%#Bind("NewProductID") %>'></asp:Textbox>
                            </EditItemTemplate>

                        </asp:TemplateField>
                            

                        <asp:TemplateField HeaderText="Sheet Product Name">
                            <ItemTemplate>
                                <asp:Label id="lblSheetProductName" runat="server" Text='<%#Bind("NewProductName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Textbox id="txtSheetProductName" runat="server" Text='<%#Bind("NewProductName") %>'></asp:Textbox>
                            </EditItemTemplate>

                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="Map to Product">
                            <ItemTemplate>
                                <asp:Label ID="lblProductId" runat="server" Text='<%#Bind("ProductID") %>' ></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>

                                <asp:objectdatasource id="ObjectDataSource1" runat="server" typename="ProductMasterBLL" 
                                    selectmethod="GetAllProductNameForDDL" ></asp:objectdatasource>

                                <asp:DropDownList ID="ddlProducts" runat="server" AutoPostBack="false" 
                                    DataSourceID="ObjectDataSource1" DataTextField="ProductName" DataValueField="ProductID"
                                    SelectedValue = '<%#Bind("ProductID") %>'  > <%--SelectedValue = '<%#Bind("ProductID") %>'--%>
                                </asp:DropDownList>

                            </EditItemTemplate>
                        </asp:TemplateField>

                        <%--<asp:TemplateField HeaderText="Update" HeaderStyle-Width="5%" HeaderStyle-HorizontalAlign="Center"
                            ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Button ID="btnUpdate" CssClass="editbuttonstyle" runat="server" CommandName="UpdateAll"
                                    ToolTip="Update All"  />
                            </ItemTemplate>
                        </asp:TemplateField>--%>

                    </Columns>
                </beg:BulkEditGridView>
            </td>
        </tr>
        <tr>
            <td align="center"> <asp:Button id="btnUpdate" OnClick="btnUpdate_Click" 
            runat="server" Text="Update" UseSubmitBehavior="false"/> </td>
        </tr>
    </table>
</div>



Code Behind:

C#
protected void btnUpdate_Click(object sender, EventArgs e)
{
    foreach (GridViewRow grv in gvUnmappedProducts.Rows)
    {
        int SheetProductID =Convert.ToInt32( ((TextBox)grv.FindControl("txtSheetProductID")).Text); // I am getting empty string here
        DropDownList ddl = (DropDownList)grv.FindControl("ddlProducts");
        int ProductMasterID =Convert.ToInt32( ddl.SelectedValue); //Getting the first item here

        ProductMasterBLL.UpdateOrderSheetProductsMapping(SheetProductID, ProductMasterID);
    }
}
Posted

1 solution

string txtSheet=(textbox)gv.Findcontrol(txt).text;
using this for checking value is getting or not
if u see that the value is fetching then use like below exp.
int SheetProductID =Convert.ToInt32((TextBox)grv.FindControl("txtSheetProductID")).Text);
 
Share this answer
 
Comments
Dinesh Prajapati 2-Feb-14 10:18am    
I aready checked it. txtSheet gives "" (i.e empty string) value. and I am not concerned with SheetProductID. I want the ProductMasterID to hold the value of ddl.SelectedValue. But it also remains unchanged. i.e. its value is the first index for all the rows. Thanks for the quick response. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900