I am using vb.net and trying to make edit/delete operation in it.
For that i have written the code to bind the grid, but when i am running the page,
Grid is not shown.
aspx for grid:
<asp:GridView ID="gv" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="ExpenceDate" HeaderText="Expence Date" />
<asp:BoundField DataField="sum(Amount)" HeaderText="Amount" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Code for binding the grid:
Try
da = New SqlDataAdapter("select expDate,sum(Amount) from expence_VB where expDate between '" + DateTime.Parse(txtFromDate.Text) + "' and '" + DateTime.Parse(txtToDate.Text) + "' group by ExpDate", con)
ds = New DataSet()
da.Fill(ds)
gv.DataSource = ds.Tables(0)
gv.DataBind()
Catch ex As Exception
End Try
Note:
I have done edit columns and turned off autogenerate fields.
For bound fields i have made DataField same as column name in query which i have written to bind the grid.
Is that any mistake in this?
please help me.
Your mistake at your query select, that query sum(Amount) not give column name. Try this: Change your select query from
da = New SqlDataAdapter("select expDate,sum(Amount) from expence_VB where expDate between '" + DateTime.Parse(txtFromDate.Text) + "' and '" + DateTime.Parse(txtToDate.Text) + "' group by ExpDate", con)
Become
da = New SqlDataAdapter("select expDate,sum(Amount) as SumAmount from expence_VB where expDate between '" + DateTime.Parse(txtFromDate.Text) + "' and '" + DateTime.Parse(txtToDate.Text) + "' group by ExpDate", con)
And then in aspx grid, you can change this code:
<asp:BoundField DataField="sum(Amount)" HeaderText="Amount" />
Become :
<asp:BoundField DataField="SumAmount" HeaderText="Amount" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.