i'm trying to update my asp.net gridview from a close method of a Growl Message.
the jquery code is:
$.gritter.add({
title: 'Success',
text: msg.d[0],
sticky: true,
after_close: function () {
__doPostBack('UpdatePanel1', '');
}
});
the gridview update panel is:
<div class="module_content">
<asp:Label runat="server" ID="Label1" />
<asp:GridView ID="grd1">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Hyperlink href="#" id="getSessionID" class="view-details" runat="server">View details</asp:Hyperlink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Message Id">
<ItemTemplate>
<%# Eval("SessionID") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sender">
<ItemTemplate>
<%# Eval("Sender") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Message Date">
<ItemTemplate>
<asp:HyperLink CssClass="msgDateDate" ID="lnkMsgDateSummary" Text='<%#DateTime.Parse(Eval("MsgDate").ToString()).ToShortDateString()%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Message Type">
<ItemTemplate>
<asp:HyperLink CssClass="msgDateType" ID="lnkMsgDateType" Text='<%# Eval("MsgType")%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reference">
<ItemTemplate>
<%# Eval("MsgRef")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<%# Eval("Status")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Within the gridview is a hyperlink, which opens up a dialog, the dialog calls a webmethod, which results in the data of the gridview changing.
I use a Growl notification to inform the end user that something has changed, and on click the ok button the after_close function is called.
When I debug the OnLoad=UpdatePanel1_Load is called, and I can see that all that changes are being bound etc.
However, my GridView total vanishes after the after_close method is run, it's not even in the DOM anymore.
Oddly though the label is there!
Can anyone tell me why my Grid vanishes?
*EDIT*
Ok, so i've added the EmptyDataText to the gridview, and the text specified in here is visible. So, even though a call the bindmethod my Gridview is empty!
On your page load event, you need to implement a check when ispostback is true, then do not load the page to default value i.e. binding of grid view.
Hope this helps.
The problem was user error. I had a case statment which was loading hte grids data based on date selected in a drop down, then drop down menu was empty, therefore my code was performing as expected, i/e no data to display you plonker :-)
Related
I want to access "Checked" property against a checkbox control in GridView, please see my aspx page code below firstly:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="cbDeleteAll" runat="server" OnCheckedChanged="cbDeleteAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cbDelete" runat="server" OnCheckedChanged="cbDelete_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Employee ID">
<ItemTemplate>
<asp:Label ID="lblEmpId" runat="server" Text='<%# Bind("DeptID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EmployeeName" HeaderText="Employee Name" />
<asp:BoundField DataField="DeptID" HeaderText="Department" />
</Columns>
</asp:GridView>
in the "cbDeleteAll_CheckedChanged" event, I would like to see the Checked property on the header template and set value to Checked property to checkboxes in the item template, see below:
as you can see, there is a red wave line under "Checked" property, when I rebuild the solution, I can see the error message as below:
so, I was totally confused I don't know why I cannot access this property in the code?
can anyone help me or give me some instructions?
Look at the error. It says WebApplication1.CheckBox. It appears you have a CheckBox class in your app and therefore you're casting to the wrong type. Don't name your classes the same thing as something built into the framework.
To find the offending file put your cursor over CheckBox in your class and press Function 12 or right click it and select Go To Definition. Then right click that class and rename it something more appropriate.
The correct CheckBox class is in System.Web.UI.WebControls namespace.
Today i was come to an issue when i was deleting a record on basis of id from grid view and i used OnRowCommand event for this.
here is my gridview code :
<asp:GridView ID="gridShow" runat="server" AutoGenerateColumns="False" PageSize="5"
AllowPaging="true" ShowHeader="false" OnRowCommand="s_index" OnRowDeleting="gridShow_RowDeleting">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtID" runat="server" Text='<%#Eval("ID") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="15%">
<ItemTemplate>
<asp:TextBox ID="txtDescription" runat="server" Text='<%#Eval("RollNumber") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtFname" runat="server" Text='<%#Eval("FirstName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="15%">
<ItemTemplate>
<asp:TextBox ID="txtLname" runat="server" Text='<%#Eval("LastName") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="15%">
<ItemTemplate>
<asp:TextBox ID="txtEmail" runat="server" Text='<%#Eval("Email") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server"></asp:Label>
<asp:HiddenField ID="hdnStatus" runat="server" Value='<%#Eval("UserName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb" runat="server" Text="Delete" CommandName="delete" CommandArgument='<%#Eval("ID") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is my C# code :
protected void s_index(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "delete")
{
oSRegisterBLL.BLLdelete(Convert.ToInt32(e.CommandArgument));
gview();
}
}
protected void gridShow_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
I successfully did this task by adding OnRowDeleting event on my grid view and definition of that event on my page behind but when i removed this first time i have come to known and issue " ASP.datashow_aspx' does not contain a definition for 'gridShow_RowDeleting' and no extension method 'gridShow_RowDeleting' accepting a first argument of type 'ASP.datashow_aspx' could be found (are you missing a using directive or an assembly reference?) "
I am confused with that why to add OnRowDeleting event on grid view with onrowcommand event ?
why i am confused because if i did not do any work with this event then why to use this event?
is there any way to work with only onrowcommand event ? or adding onrowdeleting event is essential for deletion of records from gridview?
I want to clear my mind for this ?
Your aspx markup of the GridView has declared the event handler here:
OnRowDeleting="gridShow_RowDeleting"
So when you try to remove it from the coedebehind you'll get that exception. So simply remove the event-handler and you can remove it from the codebehind.
Edit
Having a Delete-button, or even a regular button in a GridView with a CommandName of delete(which is the case here), will automatically try to fire OnRowDeleting.
So you have to add the event handler even if you don't use it or you have to rename the CommandName to e.g. "DeleteUser", otherwise you get exceptions like "The GridView 'gridShow' fired event RowDeleting which wasn't handled".
I am working on a page that is using a gridview to display data. I have some dynamically created textboxes inside an ItemTemplate which contains several textboxes per row. Now I also have an update panel that is using ajax and should only render once my link button is clicked. The datalist is bound in my code behind after the I would like this to occur without causing a full postback. However, right now when I click the link button it causes a full post-back which eliminates my dynamically created controls.
I feel I am very close to a solution. I need one of these to happen (option 1 seems more useful):
Do not cause a postback when the linkbutton is clicked, but still render my full datalist in the update panel
or
my dynamically created controls are not removed during post back.
Here is my code:
<ItemTemplate>
[ <asp:LinkButton ID="SelectCommand" CommandName="Select" runat="server" Text="+" CssClass="sunocoBold"/> ]
<%-- start sub panel--%>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Vertical"
OnItemCommand="DataList_OnItemCommand">
<ItemTemplate>
<asp:LinkButton ID="Select" CommandName="SelectCommand" CommandArgument='<%#Eval("ship_to_num")%>' runat="server" Text='<%#Eval("ship_to_num")%>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
<%-- end sub panel--%>
</ItemTemplate>
<asp:TemplateField HeaderText="Site Owner" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Panel ID="pnlNames" runat="server">
</asp:Panel>
<%-- <asp:Literal ID="NameList" runat="server" /> --%>
</ItemTemplate>
</asp:TemplateField>
UpdatePanel.Triggers is made for this!
Take a look at it here: Understanding UpdatePanel.Triggers
I have a GridView that is made up of two database fields populated via a stored procedure and then three fields for user input (two checkbox controls and one textbox) when I click on the save button I can get the information from the three controls but nothing from the two that were populated via the database. How can I get the first two fields?
<asp:GridView ID="gvA1" runat="server" AutoGenerateColumns="false" DataKeyNames="CodeNo" AutoGenerateSelectButton="false" EnablePersistedSelection="True" Visible="false">
<Columns>
<asp:TemplateField Visible="false" >
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "CodeNo")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Wrap="true" ItemStyle-Width="400px" HeaderText="Violation">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "CodeViolationCited") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="A1Accordion_cbPool" runat="server" Text="Pool:" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="A1Accordion_cbSpa" runat="server" Text="Spa:" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Additional Comments" Visible="true">
<ItemTemplate>
<asp:TextBox ID="A1Accordion_tb" runat="server" TextMode="MultiLine"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code Behind:
protected void SaveAndCollapseA1(object sender, EventArgs e)
{
//good stuff
CheckBox myCheckBox_1 = gvA1.Rows[0].FindControl("A1Accordion_cbPool") as CheckBox;
CheckBox myCheckBox_2 = gvA1.Rows[0].FindControl("A1Accordion_cbSpa") as CheckBox;
TextBox myTextBox = gvA1.Rows[0].FindControl("A1Accordion_tb") as TextBox;
//not so good stuff
String myString1 = gvA1.Rows[0].Cells[0].ToString();
String myString2 = gvA1.Rows[0].Cells[1].ToString();
}
I figured it out but I haven't been hear long enough to post the solution via the links but if you change the columns as so:
<asp:label ID="lblA1CodeNo" runat="server" text='<%# Eval("CodeNo") %>'></asp:label>
then the values are available...
Try:
<%# Bind("CodeViolationCited") %>
Instead of
<%#DataBinder.Eval(Container.DataItem, "CodeViolationCited") %>
Eval is one way, bind is two-way.
See Microsoft's documentation for data-binding expressions
Apologies for the newbie question. My client wishes me to make a small change to the gridview on his http://www.flogitdonegal.com/SearchPage.aspx page.
Note the way the Title column is a hyperlink to view more information. This comes from a 'BriefDescription' field in the database.
How can I add 250 chars from the 'FullDescription' underneath the Title in the same cell, but I dont want it be a hyperlink.
Essentially it will be 2 fields coming into the same column.
Thanks in advance for all help.
John
If this is using a GridView you are most likely using a TemplateField as it is to display the HyperLink.
Within the ItemTemplate of the TemplateField you can specify an additional Label underneath using something as follows:
<asp:Label runat="server" id="FullDescLabel" Text='<%# DataBinder.Eval(Container.DataItem, "FullDescription") %>' />
You need to use the TemplateField and here is a tutorial that explains some of the other fields that GridView offers as well.
<asp:GridView ID="gvwCompounds" runat="server" DataSourceID="objItemsFromYourDB">
<Columns>
....
<asp:TemplateField>
<ItemTemplate HeaderText="Title">
<asp:HyperLink runat="server" ID="Hperlink1" NavigateUrl='<%# Eval("BriefDescriptionUrl") %>' Text='<%# Eval("BriefDescription") %>' />
<br />
<asp:Label runat="server" ID="Label1" Text='<%# Eval("FullDescription") %>' />
</ItemTemplate>
</asp:TemplateField>
....
</Columns>
</asp:GridView>