本文介绍了如何在gridview中绑定数据而不使用任何strore prrocedure ....数据绑定视图状态..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
html代码..
html code..
<tr>
<td>
Sr. No:-
</td>
<td>
<asp:TextBox ID="txtSrno" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txtSrno" Display="None" ErrorMessage="Enter SR No"
ValidationGroup="Validate"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Iteam:-
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlstItem" runat="server" AppendDataBoundItems="true">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="ddlstItem" Display="None" ErrorMessage="Select Any One Item"
InitialValue="0" ValidationGroup="Validate"></asp:RequiredFieldValidator>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
Qty:-
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtQty" runat="server" onkeypress="return isNumberKey(event)" AutoPostBack="True"
></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtQty" Display="None" ErrorMessage="Enter Qty"
ValidationGroup="Validate"></asp:RequiredFieldValidator>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
Rate:-
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtRate" runat="server" onkeypress="return isNumberKey(event)"
ontextchanged="txtRate_TextChanged" AutoPostBack="True" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="txtRate" Display="None" ErrorMessage="Enter Rate"
ValidationGroup="Validate"></asp:RequiredFieldValidator>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
Amount:-
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtAmount" runat="server" Enabled="false" EnableTheming="True"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click"
ValidationGroup="Validate" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
ShowMessageBox="True" ShowSummary="False" ValidationGroup="Validate"
BorderColor="#003300" />
</td>
</table>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Sr No" DataField="Srno"/>
<asp:BoundField HeaderText="Item" DataField="Item" />
<asp:BoundField HeaderText="Qty" DataField="Qty" />
<asp:BoundField FooterText="Total" HeaderText="Rate" DataField="Total" />
<asp:BoundField HeaderText="Amount" />
</Columns>
</asp:GridView>
推荐答案
private DataTable DTTable
{
get
{
if (ViewState["dtTable"] != null)
return (DataTable)ViewState["dtTable"];
else
return null;
}
set
{
ViewState["dtTable"] = value;
}
}
Process for add value to view state:
Use data table to bind grid view like:
Process for add value to view state:
Use data table to bind grid view like:
DataTable dt = new DataTable();
dt.Columns.Add("Srno");
dt.Columns.Add("Item");
dt.Columns.Add("Qty");
dt.Columns.Add("Total");
dt.Columns.Add("Amount");
DTTable=dt;
Add value to dt.
Add value to dt.
DTTable.Rows.Add(1, "Item1", 10,50,200);
DTTable.Rows.Add(2, "Item2", 10,50,200);
.
.
Upto you want then bind this dt to gridview.
Upto you want then bind this dt to gridview.
GridView1.DataSource = DTTable;
GridView1.DataBind();
Please accept as answer and vote if help to you.
Please accept as answer and vote if help to you.
这篇关于如何在gridview中绑定数据而不使用任何strore prrocedure ....数据绑定视图状态..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!