0

Good day,

I was stock in the middle of developing a simple application. All i want is to bind the data into gridview, everything is fine when i binding into a single table. i need to bind my gridview using two table. my stored procedure is wroking correctly.

here is my code.

my asp code is here

<asp:GridView ID="gvCandidates" runat="server" AutoGenerateColumns="False" DataKeyNames="id">
                    <Columns>
                        <asp:CommandField HeaderText="Action" SelectText="Edit" ShowSelectButton="True"/>
                        <asp:BoundField DataField="id" HeaderText="ID"/>
                        <asp:BoundField DataField="partyId" HeaderText="PARTY NAME"/>
                        <asp:BoundField DataField="positionid" HeaderText="POSITION"/>
                        <asp:BoundField DataField="fname" HeaderText="FIRST NAME"/>
                        <asp:BoundField DataField="mname" HeaderText="MIDDLE NAME"/>
                        <asp:BoundField DataField="lname" HeaderText="LAST NAME"/>
                    </Columns>
                </asp:GridView>

my code behind is here:

 gvCandidates.DataSource = CandidatesBL.GetCandidatesList(candidates);
 gvCandidates.DataBind();

 public static IList<Candidates> GetCandidatesList(Candidates candidates)
    {
        DataTable dt = new DataTable();
        try
        {

            //
            dt = DataAccess.getDatatable(candidates.createSpDbCommand("sp_GET_CANDIDATESLIST", DBTRANS.LIST));
        }
        catch (Exception err)
        {
            string error = err.ToString();
        }

        return makeList(dt);
    }

my stored procedure is here

     SELECT A.ID
            ,B.PARTY_DESCRIPTION partyid
            ,C.POSITION_DESCRIPTION
            ,A.FNAME 
            ,A.MNAME
            ,A.LNAME
            FROM CANDIDATES A
    INNER JOIN PARTYLIST B
    ON B.ID = A.PARTYID
    INNER JOIN POSITION C
    ON C.ID = A.POSITIONID

i want to view my output in grid view like this

Action   ID      PARTY NAME          POSITION       FIRST NAME         MIDDLE NAME             LAST NAME
Edit     1    Sample Party List      PRESIDENT      Noel               Santos                  Dela Cruz

but in my ouput is like this

Action  ID  PARTY NAME   POSITION   FIRST NAME  MIDDLE NAME   LAST NAME
Edit    1      0            0          Noel        Santos      Dela Cruz

any help guys..

2
Contributors
1
Reply
3
Views
4 Years
Discussion Span
Last Post by BhuvanRam
0

Check whether you r calling the right procedure or not. As per you code

      <asp:BoundField DataField="partyId" HeaderText="PARTY NAME"/>
      <asp:BoundField DataField="positionid" HeaderText="POSITION"/>

Your data Fields are showing "ID's". So you may be confused with your exisitng flow. So check the flow properly , give your alias names correctly in the you StoredProcedure and follow the same names in GridView also

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.