使用插入链接制作geridview [英] make geridview with insert link

查看:108
本文介绍了使用插入链接制作geridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图在gridview中进行插入链接作为编辑链接已经在网格中实现

i想要当用户点击插入链接时网格重新开启行和用户在文件中输入数据除了primar键

这是我的gridview

hi all ,
iam trying to make insert link in gridview as edit link which already implemented in grid
i want when the user click on insert link the grid open anew row and the user enter data in fileds except primar key
this is my gridview

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

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

                        CellPadding="4" Height="263px" 

                        onrowcancelingedit="GridView1_RowCancelingEdit" 

                         onrowdeleting="GridView1_RowDeleting" 

                        onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" 

                         Width="1124px" onrowcommand="GridView1_RowCommand" 

                       >
                        <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>
                                  <FooterTemplate>
                                <asp:Label ID="LBLNUM" runat ="server" >
                                </asp:Label>
                                </FooterTemplate>
                                
                               
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Transaction Type ">
                            
                                 <EditItemTemplate>
                                     <asp:TextBox ID="TXTTYPE" runat="server" Text='<%# BIND("transaction_type") %>'></asp:TextBox>
                                 </EditItemTemplate>
                            
                            
                                 <ItemTemplate>
                                
                                    <asp:Label  ID="lblTrans_type" runat="server" 

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

                                        Text='<%# Bind("transaction_date") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("transaction_date") %>'></asp:Label>
                                  
                                </ItemTemplate>
                                <FooterTemplate>
                                <asp:TextBox ID ="txttransaction_date" runat ="server" >
                                </asp:TextBox>
                                
                                
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Customer Number ">
                                <EditItemTemplate>
                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("customer_num") %>'></asp:Label>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("customer_num") %>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                <asp:Label ID="textcustomer" runat ="server">
                                </asp:Label>
                                
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Service Code">
                                <EditItemTemplate>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("service_code") %>'></asp:Label>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("service_code") %>'></asp:Label>
                                </ItemTemplate>
                                <FooterTemplate>
                                <asp:Label ID="txtservicecode" runat ="server" >
                                </asp:Label>
                                
                                </FooterTemplate>
                            </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>
                                
                                <FooterTemplate>
                                <asp:TextBox ID="txtqty" runat="server">
                                </asp:TextBox>
                                
                                </FooterTemplate>
                            </asp:TemplateField>
                            
                            <asp:TemplateField HeaderText ="ACTION">
                             <FooterStyle HorizontalAlign="Right" />
                             <ItemTemplate>
                                    <asp:LinkButton ID ="BTNADD" runat="server"   CommandName="ADD" Text ="ADD" >insert</asp:LinkButton>
                             </ItemTemplate>
                            <FooterTemplate >
                            <asp:LinkButton ID ="BTNADD" runat="server"   CommandName="ADD" Text ="ADD">insert</asp:LinkButton>
                            </FooterTemplate>
                            <EditItemTemplate>
                                <asp:LinkButton ID ="BTNADD" runat="server"   CommandName="ADD" Text ="ADD" >insert</asp:LinkButton>
                            </EditItemTemplate>
                            </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>





and this is my code behind



protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{

if (e.CommandName.Equals(\"ADD\"))

{



TextBox txtAddtransaction_type = (TextBox)GridView1.FooterRow.FindControl(\"txtAddtransaction_type\");

t.Trans_type = txtAddtransaction_type.Text;

TextBox txttransaction_date = (TextBox)GridView1.Foot erRow.FindControl(\"txttransaction_date\");

t.Trans_date = txttransaction_date.Text;

Label textcustomer = (Label)GridView1.FooterRow.FindControl(\"textcustomer\");

t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());

Label txtservicecode = (Label)GridView1.FooterRow.FindControl(\"txtservicecode\");

t.Obj.Service_code = Convert.ToInt32(txtservicecode.Text);

TextBox txtqty = (TextBox)GridView1.FooterRow.FindControl(\"txtqty\");

t.Obj.Quanity = Convert.ToInt32(txtqty.Text);



int done = h.Add_transa(t);

}



}









each time running insert link when click it exception fire in

t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());



exception say input string waas not in correct format

i want to make the behaviour of insert link like edite button in case of clikikng it will open

anew row

i do not know how and i do not know if iam working in right way or not

could any one help me ?



and this is my code behind

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("ADD"))
{

TextBox txtAddtransaction_type = (TextBox)GridView1.FooterRow.FindControl("txtAddtransaction_type");
t.Trans_type = txtAddtransaction_type.Text;
TextBox txttransaction_date = (TextBox)GridView1.FooterRow.FindControl("txttransaction_date");
t.Trans_date = txttransaction_date.Text;
Label textcustomer = (Label)GridView1.FooterRow.FindControl("textcustomer");
t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());
Label txtservicecode = (Label)GridView1.FooterRow.FindControl("txtservicecode");
t.Obj.Service_code = Convert.ToInt32(txtservicecode.Text);
TextBox txtqty = (TextBox)GridView1.FooterRow.FindControl("txtqty");
t.Obj.Quanity = Convert.ToInt32(txtqty.Text);

int done = h.Add_transa(t);
}

}




each time running insert link when click it exception fire in
t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());

exception say input string waas not in correct format
i want to make the behaviour of insert link like edite button in case of clikikng it will open
anew row
i do not know how and i do not know if iam working in right way or not
could any one help me ?

推荐答案

Suggest you go thru the following tutorials:

1. Hide Primary key using DataKeyNames[^]

2. Insert, Update, Delete with Gridview ... Simple Way[^]
Suggest you go thru the following tutorials:
1. Hide Primary key using DataKeyNames[^]
2. Insert, Update, Delete with Gridview ... Simple Way[^]


Hi,



Your code is ha ving error, so you got exception say \"input string was not in correct format\".



First of all you need to correct your code.



Sol 1:



Please replace following lines



Label textcustomer = (Label)GridView1.FooterRow.FindControl(\"textcustomer\");

t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());



by



TextBox textcustomer = (TextBox)GridView1.FooterRow.FindControl(\"textcustomer\");

t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());



So the error will be removed.



Sol 2:

Second thing I observed is, you are not assigning value to \"textcustomer\" in your footer template



<FooterTemplate>

<asp:Label ID=\"textcustomer\" Text=’<%# Bind(\"customer_num\") %>’ runat =\"server\">

</asp:Label>



&l t;/FooterTemplate>
Hi,

Your code is having error, so you got exception say "input string was not in correct format".

First of all you need to correct your code.

Sol 1:

Please replace following lines

Label textcustomer = (Label)GridView1.FooterRow.FindControl("textcustomer");
t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());

by

TextBox textcustomer = (TextBox)GridView1.FooterRow.FindControl("textcustomer");
t.Cust_no = Convert.ToInt32(textcustomer.Text.ToString());

So the error will be removed.

Sol 2:
Second thing I observed is, you are not assigning value to "textcustomer" in your footer template

<FooterTemplate>
<asp:Label ID="textcustomer" Text='<%# Bind("customer_num") %>' runat ="server">
</asp:Label>

</FooterTemplate>


这篇关于使用插入链接制作geridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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