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
<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']");
if (product.val() <= 0) {
if (ShowAlert) {
ShowAlert = false;
alert("Please Map All the Products.");
}
product.addClass("ui-state-error");
IsValid = false;
}
});
if (IsValid) {
$("#<%=gvUnmappedProducts.ClientID%> tr:has(td)").each(function () {
var product = $(this).find("td:last").find("[id$='ddlProducts']");
var lblProduct = $(this).find("td:last").find("[id$='lblProductId']").attr("id");
});
$(this).dialog("close");
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
function OpenProductMapping() {
$("#<%= pmDialog.ClientID %>").dialog("open");
return false;
}
</script>
Aspx:
<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: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") %>' > <%----%>
</asp:DropDownList>
</EditItemTemplate>
</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:
protected void btnUpdate_Click(object sender, EventArgs e)
{
foreach (GridViewRow grv in gvUnmappedProducts.Rows)
{
int SheetProductID =Convert.ToInt32( ((TextBox)grv.FindControl("txtSheetProductID")).Text);
DropDownList ddl = (DropDownList)grv.FindControl("ddlProducts");
int ProductMasterID =Convert.ToInt32( ddl.SelectedValue);
ProductMasterBLL.UpdateOrderSheetProductsMapping(SheetProductID, ProductMasterID);
}
}