C# ASP.NET Application ComboBox binded to GridView Display Issue -


i creating asp.net web application display specific data sql database. have created 3 datasources each specific data want view chosen dropdownlist.

my dropdownlist coding c# side followed:

protected void dropdownlist1_selectedindexchanged(object sender, eventargs e)         {             string sourcename = dropdownlist1.selectedvalue;             gridview1.datasourceid = sourcename;             gridview1.databind();         } 

dropdownlist coding on asp.net side:

<asp:dropdownlist id="dropdownlist1" runat="server" autopostback="true" onselectedindexchanged="dropdownlist1_selectedindexchanged">             <asp:listitem value="datasource_gerneral">general overview</asp:listitem>             <asp:listitem value="datasource_portfolio">portfolio</asp:listitem>             <asp:listitem value="datasource_errorlog">error log</asp:listitem>         </asp:dropdownlist> 

the grid view coding on asp.net side followed:

<asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" borderstyle="inset" cellpadding="4" datakeynames="call_sign" datasourceid= "datasource_gerneral" font-size="smaller" forecolor="#333333" gridlines="none" height="16px" width="155px" allowpaging="true" allowsorting="true" clientidmode="autoid" horizontalalign="justify" pagesize="100" onselectedindexchanged="gridview1_selectedindexchanged1">             <alternatingrowstyle backcolor="white" forecolor="#284775" />                <columns>                 <asp:boundfield datafield="call_sign" headertext="call_sign" readonly="true" sortexpression="call_sign" />                 <asp:boundfield datafield="current_price" headertext="current_price" sortexpression="current_price" />                 <asp:boundfield datafield="stock_market" headertext="stock_market" sortexpression="stock_market" />             </columns>                <editrowstyle backcolor="#999999" />             <footerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" />             <headerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" />             <pagerstyle backcolor="#284775" forecolor="white" horizontalalign="center" />             <rowstyle backcolor="#f7f6f3" forecolor="#333333" />             <selectedrowstyle backcolor="#e2ded6" font-bold="true" forecolor="#333333" />             <sortedascendingcellstyle backcolor="#e9e7e2" />             <sortedascendingheaderstyle backcolor="#506c8c" />             <sorteddescendingcellstyle backcolor="#fffdf8" />             <sorteddescendingheaderstyle backcolor="#6f8dae" />         </asp:gridview> 

i have tested dropdownlist make sure changing datasourceid. working properly. when selected view selected dropdownlist, gridview stays same. have been looking way display new data. missing something! hoping simple line of code change gridview in runtime.

i overlooked huge game changer. wasn't changing right place. information coming same database. had write 3 if statements change command.commandtext statement. in ex.

if (dataname == "datasource_general) {     command.commandtext = " ... select..."; }  if (dataname == "datasource_portfolio") {     command.commandtext = " ... select ..."; } 

by doing data showed correctly. can configuring dropdownlist itemvalue command text calling by:

string selectstatement = dropdownlist.selectedvalue.tostring(); command.commandtext = selectstatement; 

by doing second way, achieve cleaner code.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -