Issue with gridview buttons and sqldatasource - asp.net

I have a gridview with edit and delete buttons:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" style= "-moz-border-radius: 15px;border-radius: 15px;"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="AREA" DataMember="DefaultView"
ForeColor="#333333" Height="90%" Width="90%">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="AREA" HeaderText="AREA" ReadOnly="True"
SortExpression="AREA" />
<asp:BoundField DataField="LIDER_USUARIO" HeaderText="LIDER_USUARIO"
SortExpression="LIDER_USUARIO" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="editButton" runat="server" CommandName="Edit"
ImageUrl="images/pencil1.png" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="BtnUpdate" runat="server" CommandName="Update"
Text="Edit" />
<asp:Button ID="BtnCancel" runat="server" CommandName="Cancel"
Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="deleteButton" runat="server" CommandName="Delete"
ImageUrl="images/DeleteRed1.png"
OnClientClick="return confirm('Are u sure?');" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And a sqldatasource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBUserInterfaceConnectionString %>"
DeleteCommand="DELETE FROM [TABLE] WHERE ...;"
SelectCommand="SELECT * FROM [TABLE]"
UpdateCommand="UPDATE TABLE SET ...;">
</asp:SqlDataSource>
If I link them using DatasourceID(gridview property DataSourceID="SqlDataSource1") both buttons work, but I try to do it using vb code behind they DON'T(when I press buttons nothing happens):
Protected Sub Page_Load(...
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
I need to make it using code behind. How to make them work?

Try using the DataSourceID property and point it to the ID of the data source, like this:
GridView1.DataSourceID = SqlDataSource1.ID
GridView1.DataBind()

You need to wrap them in If Not IsPostBack:
Protected Sub Page_Load(...
If Not IsPostBack Then
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
EndIf

Related

CheckedChanged Event in a Gridview checkbox to update hidden labels

I have a gridview where the first column are check boxes, the next column is ID's. I have hidden labels on the page that need to get the current ID for any check boxes checked. The labels are specific, hlbl_pain1, hlbl_pain2, hlbl_pain3. It doenst matter which label gets which ID I just need each of the 3 hidden labels to be populated with ID's. Right now on CheckedChanged the 3 labels all update with the same value. I'm having issues looping. This is in VB.
Here's my grid:
<asp:GridView ID="gv_pain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="ds_grid_pain" ForeColor="Black" GridLines="Vertical" style="text-align: left; font-size: x-small; ">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxPain" runat="server" AutoPostBack="True" Checked="false" OnCheckedChanged="CheckBoxPain_CheckedChanged" />
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("DrugID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DrugID" InsertVisible="False" SortExpression="DrugID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DrugID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_DrugID" runat="server" Text='<%# Bind("DrugID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NickName" HeaderText="NickName" SortExpression="NickName" ItemStyle-Width="150px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="DrugName" HeaderText="DrugName" SortExpression="DrugName" ItemStyle-Width="500px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan1" HeaderText="Quan1" SortExpression="Quan1">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan2" HeaderText="Quan2" SortExpression="Quan2">
<ItemStyle Wrap="False" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
Here are my labels:
<asp:Label ID="hlbl_pain1" runat="server" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain2" runat="server" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain3" runat="server" Visible="true"></asp:Label>
Here's what I'm trying to do in my CheckedChanged in the codebehind:
Protected Sub CheckBoxPain_CheckedChanged(sender As Object, e As System.EventArgs)
Dim row As GridViewRow
For Each row In gv_pain.Rows
Dim cbPain As CheckBox = row.FindControl("CheckBoxPain")
If cbPain.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain1.Text = lblDrugID.text
End If
Dim cbPain1 As CheckBox = row.FindControl("CheckBoxPain")
If cbPain1.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain2.Text = lblDrugID.text
End If
Dim cbPain2 As CheckBox = row.FindControl("CheckBoxPain")
If cbPain2.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain3.Text = lblDrugID.text
End If
Next
End Sub

How to show button on click of link button of gridview

I have a grid view and inside that i have some link button. What I am trying to do is when i clicked on link-button then two more buttons which is outside of grid view should be shown.
I searched it on google and i found some solutions as well. I set command name of linkbutton and on RowCommand event i write below code. But still those buttons are not shown to me.
Can you please help me.....
Code of Gridview:
<asp:Panel ID="Panel1" runat="server">
<fieldset>
<legend>Action</legend>
<table border='0' align='center'>
<tr>
<td align="center">
<asp:Button ID="btnShow" runat="server" Text="Show" />
</td>
<td align="center">
<asp:Button ID="btnRefresh" runat="server" Text="Reset" />
</td>
<td align="center">
<asp:Button ID="btnexptocsv" runat="server" Text="Export To CSV" Enabled="False" />
</td>
<td align="center">
<asp:Button ID="btnexptoexcel" runat="server" Text="Export To Excel" Enabled="False" />
</td>
</tr>
</table>
</fieldset>
</asp:Panel>
<asp:UpdatePanel ID="updgrd" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<fieldset>
<legend>Complaint Count </legend>
<asp:GridView ID="grd_ComplaintCount" runat="server" AutoGenerateColumns="False"
CellPadding="4" EnableModelValidation="True" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Total Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalComplaint" CommandName="lnkTotal" Text='<%#Bind("TotalComplaint") %>'
CommandArgument="Total"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Open Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalOpenComplaint" CommandName="lnkOpen"
Text='<%#Bind("TotalOpen") %>' CommandArgument="Open"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Closed Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalCloseComplaint" CommandName="lnkClosed"
Text='<%#Bind("TotalClose") %>' CommandArgument="Closed"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Reassigned Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalReassignedComplaint" CommandName="lnkReassign"
Text='<%#Bind("TotalMemberReAssign") %>' CommandArgument="Reassigned"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Observation Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalObservationComplaint" CommandName="lnkObeservation"
Text='<%#Bind("TotalObservation") %>' CommandArgument="Observation"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</fieldset>
<fieldset>
<legend>
<asp:Label runat="server" ID="Legend_Remark"></asp:Label></legend>
<asp:GridView ID="grd_ComplaintDetails" runat="server" AutoGenerateColumns="False"
CellPadding="4" EnableModelValidation="True" ForeColor="#333333" GridLines="None"
AllowPaging="True" PageSize="20">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="MemberComplaintID" DataNavigateUrlFormatString="frmComplaintActionDetails.aspx?CID={0}"
DataTextField="MemberComplaintNo" HeaderText="Complaint No" />
<asp:BoundField DataField="MemberCode" HeaderText="Member Code" />
<asp:BoundField DataField="DepartmentName" HeaderText="Service Area" />
<asp:BoundField DataField="ComplaintName" HeaderText="Type Of Complaint" />
<asp:BoundField DataField="AutoEscalation" HeaderText="Auto Escalation" />
<asp:BoundField DataField="ManualEscalation" HeaderText="Manual Escalation" />
<asp:BoundField DataField="ComplaintDate" HeaderText="Complaint Date" />
<asp:BoundField DataField="LastActionTakenBy" HeaderText="Last Action TakenBy" />
<asp:BoundField DataField="LastActionDate" HeaderText="Last ActionDate" />
<asp:BoundField DataField="Severity" HeaderText="Severity" />
<asp:BoundField DataField="ComplaintAction" HeaderText="Complaint Action" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#507CD1" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
Code of Rowcommand event:
Protected Sub grd_ComplaintCount_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd_ComplaintCount.RowCommand
ComplaintCount_Detail(e.CommandArgument)
If e.CommandName = "lnkTotal" Then
btnexptocsv.Enabled = True
btnexptoexcel.Enabled = True
ElseIf e.CommandName = "lnkOpen" Then
btnexptocsv.Enabled = True
btnexptoexcel.Enabled = True
ElseIf e.CommandName = "lnkClosed" Then
btnexptocsv.Enabled = True
btnexptoexcel.Enabled = True
ElseIf e.CommandName = "lnkReassign" Then
btnexptocsv.Enabled = True
btnexptoexcel.Enabled = True
ElseIf e.CommandName = "lnkObeservation" Then
btnexptocsv.Enabled = True
btnexptoexcel.Enabled = True
Else
btnexptoexcel.Enabled = False
btnexptocsv.Enabled = False
End If
End Sub
My Question :How to Show Buttons (which is outside of grid view) after Link Button Clicked
(which is inside of gridview)
Put your buttons inside the UpdatePanel

Paging for Gridview doesn't work correct

I have a search page. In list the search results are displayed.
When I select another page from page numbers, the search result is disappeared and show the list like the page is refreshed. What should I do? I tried OnSelectedIndexChanged and OnSelectedIndexChanging. And didn't work. Thank you.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="ahsun" ForeColor="#333333" GridLines="None" Width="100%"
DataKeyNames="SICIL_NO" OnSelectedIndexChanged="LinkButton1_Click" CssClass="icerik" o >
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"
CssClass="hover" Text="Seç"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Adı" SortExpression="ADI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" Text='<%# Bind("ADI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Soyadı" SortExpression="SOYADI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton4" runat="server" Text='<%# Bind("SOYADI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birimi" SortExpression="BIRIMI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton5" runat="server" Text='<%# Bind("BIRIMI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Görevi" SortExpression="GOREVI">
<ItemTemplate>
<asp:LinkButton ID="LinkButton6" runat="server" Text='<%# Bind("GOREVI") %>' CausesValidation="False"
CommandName="Select" CssClass="hover"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="ahsun" runat="server" ConnectionString="<%$ ConnectionStrings:oraLiveConnectionString %>"
ProviderName="<%$ ConnectionStrings:oraLiveConnectionString.ProviderName %>"
SelectCommand="select SICIL_NO, ADI, SOYADI, BIRIMI ,GOREVI,PERSON_ID from xxah_hr_calisanlar WHERE SICIL_NO <> '01470' "></asp:SqlDataSource>
<br />
<asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4" DataKeyNames="SICIL_NO"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Height="50px"
Width="100%" CaptionAlign="Left" AutoGenerateRows="False" CssClass="icerik">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#2461BF" />
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" Width="75%" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" Width="25%" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"
Width="25%" />
<AlternatingRowStyle BackColor="White" />
<Fields>
<asp:BoundField DataField="ADI" HeaderText="Adı" SortExpression="ADI" />
<asp:BoundField DataField="SOYADI" HeaderText="Soyadı" SortExpression="SOYADI" />
<asp:BoundField DataField="BIRIMI" HeaderText="Birimi" SortExpression="BIRIMI" />
<asp:BoundField DataField="GOREVI" HeaderText="Görevi" SortExpression="GOREVI" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:oraLiveConnectionString %>" EnableCaching="True"
ProviderName="<%$ ConnectionStrings:oraLiveConnectionString.ProviderName %>"
SelectCommand="select c.* from TABLE c where c.SICIL_NO=:sicil" >
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="sicil" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
For pagination You need to work on PageIndexChanging.Nothing to do with OnSelectedIndexChanged.
For Example:
Method
protected void BindData()
{
string strConnection = "Data Source=.; uid=sa; pwd=wintellect;database=Rohatash;";
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Userinfo", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
PageIndexChanging
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindData();
}
Try enabling ViewState on the datasource in your aspx page by adding EnableViewState="true" and ViewStateMode="Enabled"

visual studio doesn't see the dropdownlist for trigger

I have a VB.NET / ASP.NET web application. I added a dropdownlist into FooterTemplate of a Gridview. And I used ajax for postbacks. But when I add the dropdown to the triggers, vs gives me that error :
A control with ID 'DropDownList2' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
ASP.NET code is like that :
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" Width="329px" AutoGenerateColumns="False"
Font-Names="Arial" Font-Size="11pt"
AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green"
AllowPaging="True" ShowFooter="True" OnPageIndexChanging="OnPaging"
Style="margin-right: 0px" BackColor="White" BorderColor="#336666"
BorderStyle="Double" BorderWidth="3px" CellPadding="3"
GridLines="Horizontal">
<AlternatingRowStyle BackColor="#C2D69B" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="lnkRemove" runat="server" CommandArgument='<%# Eval("il_ad")%>'
OnClientClick="return confirm('SİLMEK İSTEDİĞİNİZDEN EMİN MİSİNİZ?')"
Text="SİL" OnClick="DeleteDURUM"></asp:Button>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="EKLE" OnClick="AddNewDURUM" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField EditText="DEĞİŞTİR" ButtonType="Button"
CancelText="İPTAL" DeleteText="SİL" UpdateText="KAYDET" ControlStyle-Width="70PX"
CausesValidation="False">
<ControlStyle Width="70px" />
</asp:CommandField>
<asp:TemplateField ItemStyle-Width="30px" HeaderText="YTM No">
<ItemTemplate>
<asp:Label ID="lblytm_id" runat="server" Text='<%# Eval("ytm_id")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="30px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="İl">
<ItemTemplate>
<asp:Label ID="il_ad" runat="server" Text='<%# Eval("il_ad")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="il_ad" runat="server" Text='<%# Eval("il_ad")%>'></asp:TextBox>
</EditItemTemplate>
<!-- Dropdownlist is here : -->
<FooterTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" Width= "120px" DataSourceID="iller_yukle" AutoPostBack="True">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#000066" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#487575" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#275353" />
</asp:GridView>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView2" />
<asp:AsyncPostBackTrigger ControlID="DropDownList2" /> <!-- Error is here -->
</Triggers>
</asp:UpdatePanel>
where is the mistake, I couldn't figure it out, thanks..
The DropDownList only exists within the GridView and you cannot access controls within a GridView directly.
You would need to dynamically add the trigger to the UpdatePanel after you have bound the GridView.
To dynamically add it you would need to first Bind your gridview, then register the trigger
AsyncPostBackTrigger apt = new AsyncPostBackTrigger();
apt.ControlID = ((Button)this.GridView1.FooterRow.FindControl("btnTrigger")).UniqueID;
apt.EventName = "Click";
this.UpdatePanel1.Triggers.Add(apt);
In this example I am using a button's click event to trigger the UpdatePanel. You can adapt this to the DropDownList
Generally the mistake is that you don't need to specify triggers for controls inside an UpdatePanel till you don's set ChildrenAsTriggers="false" on that UpdatePanel

ASP gives this error message: Both DataSource and DataSourceID are defined on 'profileGridView'. Remove one definition

<code>
<asp:Content ID="manageProfileContent" runat="server" ContentPlaceHolderID="mainContentPlaceHolder">
<div class="Menu">
<asp:Label ID="manageProfileTitle" runat="server" Text="Manage Profile" />
</div>
<br />
<asp:Panel ID="manageProfileMessagePanel" runat="server">
<asp:Label ID="manageProfileMessageLabel" runat="server" Font-Names="Sans-serif" Font-Size="Medium" Font-Bold="true" ForeColor="Red" Text="" />
</asp:Panel>
<br />
<asp:GridView ID="profileGridView" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
CellPadding="3" ForeColor="Black" GridLines="Vertical"
DataKeyNames="userid" DataSourceID="profileGridViewSqlDataSource">
<FooterStyle BackColor="#CCCCCC" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="userid" HeaderText="userid" ReadOnly="True"
SortExpression="userid" />
<asp:CheckBoxField DataField="administrator" HeaderText="administrator"
SortExpression="administrator" />
<asp:CheckBoxField DataField="policy_originator" HeaderText="policy_originator"
SortExpression="policy_originator" />
<asp:CheckBoxField DataField="policy_approver" HeaderText="policy_approver"
SortExpression="policy_approver" />
<asp:CheckBoxField DataField="employee" HeaderText="employee"
SortExpression="employee" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="profileGridViewSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:policymgmConnectionString %>"
SelectCommand="SELECT [userid], [administrator], [policy_originator], [policy_approver], [employee] FROM [tbl_profile]">
</asp:SqlDataSource>
</asp:Content>
</code>
Do not specify profileGridView.Datasource = datatable; profileGridView.DataBind(); when you have already specified datasourceid for the gridview. As the error clearly says, either remove datasourceid for the gridview or the lines profileGridView.Datasource = datatable; profileGridView.DataBind(); from your code!

Resources