payal.priyadarshini-gmail
-
8/24/2010 1:03:50 PM
GridView RowUpdating event
Hi,
I have a gridview. In the rowupdating event, the txtbox returns null. I have enabled viewstate for the gridview. But still it does not work. I have made this in Kentico. Please help.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" EnableModelValidation="True" OnRowUpdating="GridView1_RowUpdating" > <Columns> <asp:CommandField ShowDeleteButton="True" CausesValidation="false" ShowEditButton="True" ControlStyle-Width="100px" /> <asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Name" SortExpression="name"> <ItemTemplate> <asp:Label ID="lblRegionName" runat="Server" Text='<%# Bind("name") %>' Width="200px"></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" ID="EditRegionName" OnTextChanged="EditRegionName_Updated" Text='<%# Bind("name") %>' Width="200px" /> </EditItemTemplate> <FooterTemplate> <asp:TextBox runat="server" ID="InsertRegionName" Text='' Width="200px" /> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderText="Archived" SortExpression="IsArchive"> <ItemTemplate> <asp:CheckBox ID="lblArchive" Enabled="false" runat="Server" Checked='<%# DataBinder.Eval(Container.DataItem, "archived") %>' Width="100px" /> </ItemTemplate> <EditItemTemplate> <asp:CheckBox runat="server" OnCheckedChanged="EditArchive_CheckedChanged" ID="EditArchive" Width="100px" /> </EditItemTemplate> <FooterTemplate> <asp:CheckBox runat="server" ID="InsertArchive" Checked="false" Width="100px" /> </FooterTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:LinkButton ID="btnHistory" runat="server" Text="History"></asp:LinkButton> <ajaxToolkit:ModalPopupExtender OkControlID="OkButton" ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground" TargetControlID="btnHistory" PopupControlID="Panel1" /> <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none"> <div> <iframe frameborder="0" src="/CMSWebParts/MSM/RoundTableAfrica/Beheer/History.aspx?id=<%# DataBinder.Eval(Container.DataItem, "id") %>" width="500px" height="100%" scrolling="no"></iframe> <br /> <asp:Button ID="OkButton" runat="server" Text="OK" CausesValidation="false" Width="50" /> </asp:Panel> </div> </ItemTemplate> <EditItemTemplate> </EditItemTemplate> <FooterTemplate> <asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="Insert_Click" /> </FooterTemplate> </asp:TemplateField> </Columns> <EmptyDataTemplate> Region Name:<asp:TextBox runat="server" ID="NoDataRegionName" /> Archived:<asp:CheckBox runat="server" ID="NoDataIsArchive" /> <asp:Button runat="server" ID="NoDataInsert" CssClass="contentButton" Text="Insert" OnClick="Button1_Click" /> </EmptyDataTemplate> </asp:GridView> <asp:Button runat="server" ID="Add" Text="Add" OnClick="Add_Click" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RTAConnectionString%>" ProviderName="System.Data.SqlClient" SelectCommand="select * from [spiderwebs_region] order by name " UpdateCommand="UpdateRegionWithHistory" UpdateCommandType="StoredProcedure" DeleteCommand="DeleteRegionWithHistory" DeleteCommandType="StoredProcedure" OnInserting="Sqldatasource1_Inserting" OnInserted="Sqldatasource1_Inserted" InsertCommand="InsertRegionWithHistory" InsertCommandType="StoredProcedure"> <DeleteParameters> <asp:Parameter Name="id" Type="Int32" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="action_time" Type="DateTime" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="content_type_id" Type="Int32" /> <asp:Parameter Name="object_repr" Type="String" /> <asp:Parameter Name="action_flag" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource>
Code Behind:
protected void Page_Load(object sender, EventArgs e) { GridView1.DataBind(); }
protected void GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e) { int index = e.RowIndex; GridViewRow currentrow = ((GridView)sender).Rows[index];
TextBox txtbox = (TextBox)currentrow.FindControl("EditRegionName"); CheckBox isarchive = (CheckBox)currentrow.FindControl("EditArchive");
e.NewValues["name"] = txtbox.Text; e.NewValues["archived"] = isarchive.Checked;
GridView1.EditIndex = -1; GridView1.DataBind(); }
|