Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All

Having this error coming.

I tried to change the undernoted to GridView1.DataSourceID =
dsas

but it gave an error.

I also tried to change

<pre> AutoGenerateColumns="False" BackColor="#FFFFCC" DataSourceID="SqlDataSource1" 

to <pre> AutoGenerateColumns="False" BackColor="#FFFFCC" DataSource="SqlDataSource1" 

and it also was no ok.

What  do I do to resolve this issue?

*************************************
<pre> <td class="style32" colspan="8">
                <div style="height: 80px; text-align: left;" align="center">
                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" BackColor="#FFFFCC" DataSourceID="SqlDataSource1" 
                        Font-Overline="False" Font-Size="X-Small" ForeColor="Black" 
                        onselectedindexchanged="GridView1_SelectedIndexChanged" PageSize="5" 
                        style="margin-right: 91px" Width="918px">


***************************************
public void LoadSearch()
{


try
{
SqlConnection connect = new SqlConnection();
connect.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
connect.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM LOANS order by ID_CODE", connect);

SqlCommand SqlCmd = new SqlCommand("sp_searchActLoan", connect);
SqlCmd.CommandType = CommandType.StoredProcedure;

SqlCmd.Parameters.AddWithValue("@searchString", txt_Search.Text);
SqlCmd.ExecuteNonQuery();

SqlDataAdapter daa = new SqlDataAdapter();
daa.SelectCommand = SqlCmd;

DataSet dsas = new DataSet();
daa.Fill(dsas, "searchResults");
GridView1.DataSource = dsas;
//GridView1.DataSourceID = null;
GridView1.DataSource = dsas;
GridView1.DataBind();
connect.Close();


------------------------------------------
------------------------------------------
Posted
Updated 21-Jun-14 19:50pm
v2

1 solution

Do as the message tells you!
You initialize DataSourceID in the markup, than initialize DataSource from the code-behind...
HTML
DataSourceID="SqlDataSource1"

C#
GridView1.DataSource = dsas;

The GridView can't decide which to use for data rendering. You have to choose!!! Remove one of them...
 
Share this answer
 
Comments
Member 10744248 22-Jun-14 2:25am    
The Datasource in the markup was generated automatically when I pulled the gridview.

However when I tried to change

GridView1.DataSource = dsas;

to

GridView1.DataSourceId = dsas;

it gave an error

when I also removed it I was not getting the search results required.
Kornfeld Eliyahu Peter 22-Jun-14 2:33am    
Read carefully my solution = 'Remove one of them'!!! Choose your option of DataSourceID or DataSource and remove the other one!
Member 10744248 22-Jun-14 4:47am    
The issue at hand is that I'm doing a query which will return results to a gridview.

There is the need to have enable select to select the results from the query to populate the form.

Is there a way to program the gridview?

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900