c# - How to run SelectCommand in <asp:SqlDataSource> tag -


i making querystring parameter ,so have 2 .aspx forms. 1 form default.aspx contains 3 fields sid, firstname, lastname. when submit values, values saved in database.now want show data on grid particular sid on default2.aspx. grid takes data through sqldatasource.so want call sqldatasource on button click , grid should show data particular sid on default2.aspx.

default.aspx :

<body>   <form id="form1" runat="server">   <div>    </div> <table cellpadding="2" cellspacing="5">     <tr>         <td>             <asp:label id="lblid" runat="server" text="sid"></asp:label>         </td>         <td>             <asp:textbox id="tbid" runat="server"></asp:textbox>         </td>     </tr>     <tr>         <td>             <asp:label id="lblname" runat="server" text="firstname"></asp:label>         </td>         <td>             <asp:textbox id="tbfirstname" runat="server"></asp:textbox>         </td>     </tr>     <tr>         <td>             <asp:label id="lbllastname" runat="server" text="lastname"></asp:label>         </td>         <td>             <asp:textbox id="tblastname" runat="server"></asp:textbox>         </td>     </tr>     <tr>         <td>         </td>         <td>             <asp:button id="btnsubmit" runat="server" text="submit"                  onclick="btnsubmit_click1" width="102px" />         </td>     </tr> </table> <br />  </form> </body> 

default2.aspx :

<body> <form id="form1" runat="server"> <div>      <table cellpadding="2" cellspacing="5">         <tr>             <td>                 sid</td>             <td>                 <asp:textbox id="tbid" runat="server"></asp:textbox>             </td>         </tr>          <tr>             <td>             </td>             <td>                 <asp:button id="btnsearch" runat="server" text="search"                      onclick="btnsearch_click" />             </td>         </tr>      </table>   </div>  <br />  <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false"      autogenerateselectbutton="true"      datasourceid="sqldatasource1" enablemodelvalidation="true"      onrowcommand="gridview1_rowcommand"> <columns>          <asp:templatefield headertext="sid">           <itemtemplate>            <asp:label id="lblsid" runat="server" text='<%# bind("sid") %>'></asp:label>            </itemtemplate>          </asp:templatefield>          <asp:templatefield headertext="firstname">            <itemtemplate>           <asp:label id="lblfirstname" runat="server" text='<%# bind("firstname")%>'>            </asp:label>           </itemtemplate>         </asp:templatefield>          <asp:templatefield headertext="lastname">            <itemtemplate>   <asp:label id="lbllastname" runat="server" text='<%# bind("lastname")%>'></asp:label>            </itemtemplate>         </asp:templatefield>  </columns> </asp:gridview>  <asp:sqldatasource id="sqldatasource1" runat="server"      connectionstring="<%$ connectionstrings:testconnectionstring %>"       selectcommand="select * [student] sid = @tbid">  <selectparameters>         <asp:querystringparameter name="sid" querystringfield="sid" /> </selectparameters> </asp:sqldatasource> </form> </body> 

i want call sqldatasource1 on button click like..

default2.aspx.cs :

 protected void btnsearch_click(object sender, eventargs e)  {          string sid = tbid.text;     sqldatasource1.databind();   } 

you don't need button click. sqldatasource executes on every post back. search button going issue post back. going need change few things. first need parameters right, remove one:

<asp:querystringparameter name="sid" querystringfield="sid" /> 

and put 1 in place:

<asp:controlparameter controlid="tbid" propertyname="text" name="tbid" /> 

and remove of code:

protected void btnsearch_click(object sender, eventargs e) {          string sid = tbid.text;     sqldatasource1.databind(); } 

and sqldatasource tied directly control value, when user puts in new control value , clicks button applied , new data retrieved without of interaction.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -