如何在gridview中绑定数据而不使用任何strore prrocedure ....数据绑定视图状态.. [英] how to bind data in gridview without using any strore prrocedure....data bind with view state..

查看:76
本文介绍了如何在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" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                </td>
            </tr>
            <tr>
                <td>

                    &nbsp;</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>

推荐答案

without using any stored procedure in the sense...

do you want to bind the data after postback also...

In that case, call the stored procedure in the pageload event and set the resu lt to a ViewState and then bind this ViewState to GridView...



Please find a sample at

viewstate-with-example-in-aspnet-c.html



gridview-loses-data-during-postback
without using any stored procedure in the sense...
do you want to bind the data after postback also...
In that case, call the stored procedure in the pageload event and set the result to a ViewState and then bind this ViewState to GridView...

Please find a sample at
viewstate-with-example-in-aspnet-c.html

gridview-loses-data-during-postback


Refer this link



GridView Paging and Sorting in ASP.NET Without Using a DataSource[^]
Refer this link

GridView Paging and Sorting in ASP.NET Without Using a DataSource[^]


Declare Property for datatable:

Declare Property for datatable:
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 ....数据绑定视图状态..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆