Execute Update on DropDownList change - c#

At the moment, I have a GridView with the following in the ItemTemplate:
<asp:LinkButton ID="lbEdit" runat="server" CommandName="Edit">
<asp:Label ID="Label6x" runat="server" Text='<%# Bind("progress_full") %>' /></asp:LinkButton>
This works fine and when I click on it, it displays the EditTemplate which currently contains the following:
<asp:DropDownList ID="DropDownList3" runat="server"
SelectedValue='<%# Bind("progress") %>'>
<asp:ListItem Value="0">In queue</asp:ListItem>
<asp:ListItem Value="1">Being worked on</asp:ListItem>
<asp:ListItem Value="2">Complete</asp:ListItem>
</asp:DropDownList><br />
<asp:LinkButton ID="lbUpdate" runat="server" CommandName="Update" Text="Update" />
How can I get the dropdown to automatically execute the Update command when it is changed, instantly returning back to the ItemTemplate, instead of me making the change to the DropDown and having to click Update?

You add AutoPostBack="true" to your DropDownList and set OnSelecIndexChanged="DropDownList1_SelectedIndexChanged"
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//execute here your update
......
}

Related

DataGrid fetching particular row on dropdownselectedindex value change event

Im working on one small project.Using Datagrid in that
<asp:DataGrid ID="dgShowTiming"
runat="server"
AutoGenerateColumns="false"
OnItemCreated="dgShowTiming_ItemCreated">
<Columns>
<asp:TemplateColumn HeaderText="HOUR">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingsHours"
runat="server"
CssClass="field1"
DataSource="<%#Hour()%>"
DataTextField="Hours"
DataValueField="Hours">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="MINUTE">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingsminutes"
runat="server"
CssClass="field1"
DataSource="<%#Minute()%>"
DataTextField="Minutes"
DataValueField="Minutes">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="AM/PM">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingAMPM"
runat="server"
CssClass="field1"
onchange="GetCountryDetails()">
<asp:ListItem>AM</asp:ListItem>
<asp:ListItem>PM</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:DropDownList ID="ddlShowTimingDescription"
runat="server"
DataSource="<%#Description()%>"
DataTextField="ShowTimeDesc"
DataValueField="ShowTimeDescID"
CssClass="field1">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Tax Details">
<ItemTemplate>
<asp:Label ID="lblRowID"
runat="Server"
Text="View"
Style="cursor: pointer;"
onclick="FilmTaxDetailsOpen(this);"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
So Now My problem in this Grid is i have to on selectedindexchange value of dropdown ddlShowTimingAMPM i want to change the description as NOON or morning or evening..Problem im facing is how to fetch the values of 3 dropdownlist selected , based on that only im changing the description.
try this 100% working and tested
Once you Find row then from that row you can find all Controls inside that row. You can same apply for other DropDownList and set AutoPostBack="true" for all DropDownList
protected void ddlShowTimingsHours_OnSelectedIndexChanged(object sender, EventArgs e)
{
DataGridItem item = (DataGridItem)((DropDownList)sender).Parent.Parent;
DropDownList ddlShowTimingsHours = (DropDownList)item.FindControl("ddlShowTimingsHours");
DropDownList ddlShowTimingsminutes= (DropDownList)item.FindControl("ddlShowTimingsminutes");
DropDownList ddlShowTimingAMPM= (DropDownList)item.FindControl("ddlShowTimingAMPM");
}

get object from listview after clicking a button

I'm trying to get the original object back from a listview, when I click on the button.
I thought it was in e.Item.DataItem but that always seems to be null.
<form runat="server">
<asp:ListView ID="ListList" runat="server">
<ItemTemplate>
<asp:TextBox ID="tbCompanyName" runat="server" Text='<%# Eval("CompanyName") %>'></asp:TextBox>
<asp:TextBox ID="tbEmailAdress" runat="server" Text='<%# Eval("EmailAddres") %>'></asp:TextBox>
<asp:DropDownList ID="ddlAccountManagers" AutoPostBack="True" runat="server" />
<asp:Button runat="server" Text="Create or Update Account" CommandArgument='<%# Container.DataItem.ToString() %>' />
<br />
</ItemTemplate>
</asp:ListView>
</form>
private void ListList_ItemCommand(object sender, ListViewCommandEventArgs e)
{
}
You need to keep the original datasource in session and get the real values while clicking a button.

Adding dropdown list to columns in gridview

I have a grid and I want to set a dropdown list with Yes & No for some columns. I am not able to put that dropdown list like I mentioned below. Its because I use checkbox in the grid to edit the rows. So even if I put these I am not able to see the drop down when I click the checkbox to edit.
<asp:TemplateField HeaderText="Lead" ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblLead" runat="server" Text='<%# Bind("Lead") %>'></asp:Label>
<asp:TextBox ID="txtLead" runat="server" Text='<%# Bind("Lead") %>' Visible="false"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="100px" />
<EditItemTemplate>
<asp:DropDownList id="ddlLead" runat="server">
<asp:ListItem Value="Yes"> Yes </asp:ListItem>
<asp:ListItem Value="No"> No </asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
Try this
protected void grdVw_RowEditing(object sender, GridViewEditEventArgs e)
{
grdVw.EditIndex = e.NewEditIndex;
/* Insert specific editing logic here */
grdBind();//method to bind gridview
}
First you gotta make sure you are setting the mode to Edit. For this I use the default buttons, and you are using checkboxes, they should both work:
<asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing">
<Columns>
<asp:CommandField ShowEditButton="True" />
<%--Other columns here--%>
</Columns>
</asp:GridView>
Then, you need to handle the RowEditing event, by setting the EditIndex to the index of the row you want to edit, and re-bind the GridView:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
setDataSource(); //this sets the data source of the grid, and re-binds it.
}

asp.net drop down list selectedindexchanged firing slowly compared to button click within update panel

I have a few buttons within an update panel. I have now been asked to replace the buttons with
a drop down list . I see that the selectedindexchanged event on the drop down list is much slower
than the button click event. I have the code below. Can anyone point me as to why it is happenning ?
or what I can do to make the selectedindexchanged event response faster .
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<div class="ui-widget-header" style="display: inline;">
<asp:Label ID="lblRefresh" runat="server" Text="Refresh Interval:" CssClass="label"
ForeColor="Black"></asp:Label>&nbsp&nbsp&nbsp
<asp:LinkButton ID="btnOFF" runat="server" OnClick="btnOFF_Click" Text="Off">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn60SEC" runat="server" OnClick="btn60SEC_Click" Text="1Min">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn5MIN" runat="server" OnClick="btn5MIN_Click" Text="5Min">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn10MIN" runat="server" OnClick="btn10MIN_Click" Text="10Min">
</asp:LinkButton>&nbsp
<asp:LinkButton ID="btn15MIN" runat="server" OnClick="btn15MIN_Click" Text="15Min">
</asp:LinkButton>
<asp:DropDownList ID="ddlRefresh" runat="server" onselectedindexchanged="ddlRefresh_SelectedIndexChanged">
<asp:ListItem Text="OFF" Value="0"></asp:ListItem>
<asp:ListItem Text="5MIN" Value="5"></asp:ListItem>
<asp:ListItem Text="10MIN" Value="10"></asp:ListItem>
</asp:DropDownList>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlRefresh" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
Well what seems to work for me right now is to set AutoPostback = "true" for the dropdownlist .
<asp:DropDownList ID="ddlRefresh" runat="server" onselectedindexchanged="ddlRefresh_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="OFF" Value="0"></asp:ListItem>
<asp:ListItem Text="5MIN" Value="5"></asp:ListItem>
<asp:ListItem Text="10MIN" Value="10"></asp:ListItem>
</asp:DropDownList>
I had the same problem and I found that the problem is with _destroyTree. Check it here (https://siderite.dev/blog/very-slow-updatepanel-refresh-when.html).

DropDown not firing OnSelectedIndexChanged

I have a page with dropdown list
<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Cellsite</asp:ListItem>
<asp:ListItem>Agreement</asp:ListItem>
<asp:ListItem>Event</asp:ListItem>
<asp:ListItem>User</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server" Width="100%">
<Behaviors>
<ig:Sorting>
</ig:Sorting>
</Behaviors>
</ig:WebDataGrid>
code behind is
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
EntityName.Text = DropDownList1.SelectedItem.Text;
}
For somereason the label is never updated the event selectedindexchanged is not firing at all I need to add a dynamic grid in this event. Any clue?
You need to add AutoPostBack on the dropdown
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
You can actually tell that there is no post back when you do not have the AutoPostBack=true attribute.
set dropdownlist property AutoPostBack="true"
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Cellsite</asp:ListItem>
<asp:ListItem>Agreement</asp:ListItem>
<asp:ListItem>Event</asp:ListItem>
<asp:ListItem>User</asp:ListItem>
</asp:DropDownList>

Categories

Resources