本文介绍了在editmode中的gridview中绑定dropdawnlist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧,

i有一个gridview包含列名事务类型在显示模式下它将是标签

在editemode它应该是dropdawnlist

运行页面时加载网格

如果出现点击编辑链接异常,因为dropdawnlist

i试图找到如何在编辑模式下绑定它以及那是什么但仍然存在相同的问题

可以帮助我吗?这是我的代码

hi all,
i have gridview contain column name "transaction type " in display mode it will be label
in editemode it should be dropdawnlist
when running the page it load the grid
in case of click edit link exception appear because dropdawnlist
i try to find how to bound it in edit mode and that what iam doing but still the same problem
could any one help me ? this is my code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 

                        BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" 

                        CellPadding="4" Height="222px" 

                        onrowcancelingedit="GridView1_RowCancelingEdit" 

                        onrowdatabound="GridView1_RowDataBound" onrowdeleting="GridView1_RowDeleting" 

                        onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" 

                       >
                        <RowStyle BackColor="White" ForeColor="#003399" />
                        <Columns>
                            <asp:TemplateField HeaderText="Transaction Number">
                           
                                 <ItemTemplate>
                                    <asp:Label ID="lbltransaction_num" runat="server" 

                                        Text='<%#Bind("transaction_num")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Label ID="lbltrans_num" runat="server" 

                                        Text='<%#Bind("transaction_num")%>'></asp:Label>
                                </EditItemTemplate>
                               
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Transaction Type ">
                                <EditItemTemplate>
                                    <asp:DropDownList ID="DropDownList1" runat="server" 

                                        SelectedValue='<%# Bind("transaction_type") %>'>
                                    </asp:DropDownList>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblTrans_type" runat="server" 

                                        Text='<%# Bind("transaction_type") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Transaction Date">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox1" runat="server" 

                                        Text='<%# Bind("transaction_date") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("transaction_date") %>'></asp:Label>
                                    <br />
                                    <br />
                                    <br />
                                    <br />
                                    <br />
                                    <br />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Customer Number ">
                                <EditItemTemplate>
                                    <asp:DropDownList ID="DropDownList2" runat="server" 

                                        SelectedValue='<%# Bind("customer_num") %>'>
                                    </asp:DropDownList>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("customer_num") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Service Code">
                                <EditItemTemplate>
                                    <asp:DropDownList ID="DropDownList3" runat="server" 

                                        SelectedValue='<%# Bind("service_code") %>'>
                                    </asp:DropDownList>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("service_code") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Quantity">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("qty") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("qty") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:CommandField ShowEditButton="True" />
                            <asp:CommandField ShowSelectButton="True" />
                        </Columns>
                        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                        <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                       
                        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
                    </asp:GridView>













protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
       {


           GridView1.EditIndex = e.NewEditIndex;
           GridView1.DataSource = h.get_transactiondetails_bal().Tables [0];
           GridView1.DataBind();




       }



















protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(GridView1.EditIndex ==e.Row .RowIndex &&  e.Row.RowType ==DataControlRowType.DataRow)
    {
        DropDownList dr = (DropDownList)e.Row.Cells[1].FindControl("DropDownList1");
        dr.DataSource = h.get_transactiondetails_bal().Tables[0].Columns["transaction_type"];
        dr.DataTextField = "transaction_type";
        dr.DataValueField = "transaction_type";
        dr.DataBind();
    }
}











also i did not know the line e.Row.RowType ==DataControlRowType.DataRow what does it mean

thanks and regards






also i did not know the line e.Row.RowType ==DataControlRowType.DataRow what does it mean
thanks and regards

推荐答案


这篇关于在editmode中的gridview中绑定dropdawnlist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:32