帮助我使用带有存储过程的gridview吗? [英] Help me using gridview with stored proceduce?

查看:87
本文介绍了帮助我使用带有存储过程的gridview吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


帮我使用带有存储过程的gridview吗? [ ^ ]
[/EDIT]


Help me using gridview with stored proceduce?[^]
[/EDIT]

<div>languages:<asp:DropDownList ID="DropDownList1" runat="server"
           AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="languages"
           DataValueField="id_lang">
       </asp:DropDownList>
       <asp:SqlDataSource ID="SqlDataSource1" runat="server"
           ConnectionString="<%$ ConnectionStrings:ispaceconnectstring %>"
           SelectCommand="SELECT [id_lang], [languages] FROM [tb_languages]">
       </asp:SqlDataSource>
   </div>
   <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#3E7C92"
       GridLines="None" Width="750px" AllowPaging="True"
       DataSourceID="ObjectDataSource1">
       <RowStyle BackColor="#eff0f2" ForeColor="#333333" Height="40px" />
       <FooterStyle BackColor="#f0f0f0" Font-Bold="True" ForeColor="White" />
       <PagerStyle BackColor="#3e7c92" ForeColor="#333333" HorizontalAlign="Center" />
       <SelectedRowStyle BackColor="#e5e5e5" Font-Bold="True" ForeColor="Navy" Height="30px" />
       <HeaderStyle BackColor="#3e7c92" Font-Bold="True" ForeColor="White" Height="50px"/>
       <AlternatingRowStyle BackColor="White" />
   </asp:GridView>
   <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
       DeleteMethod="getmenulangid" InsertMethod="getmenulangid"
       SelectMethod="getmenulangid" TypeName="ispace.Class.cls_getmenubylangid"
       UpdateMethod="getmenulangid">
       <DeleteParameters>
           <asp:Parameter Name="id_lang" Type="Int32" />
       </DeleteParameters>
       <UpdateParameters>
           <asp:Parameter Name="id_lang" Type="Int32" />
       </UpdateParameters>
       <SelectParameters>
           <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="id_lang"
               PropertyName="SelectedValue" Type="Int32" />
       </SelectParameters>
       <InsertParameters>
           <asp:Parameter Name="id_lang" Type="Int32" />
       </InsertParameters>
   </asp:ObjectDataSource>


public DataTable getmenulangid(int id_lang)
        {
            SqlConnection mySqlConnection = new SqlConnection();// sql Product tra ve Product.ProductID=@ProductID

            SqlCommand mySqlCommand = new SqlCommand();
            DataTable tblData = new DataTable();
            // Khai báo câu truy vấn
            SqlConnection conn = new SqlConnection(Config.ispaceconnect);
            try
            {
                //OleDbConnection conObj = new OleDbConnection(connectString); 
                conn.Open();
                SqlCommand comm = new SqlCommand("usp_hienvd_tblang_getmenubylangid", conn);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.Add("@id_lang", SqlDbType.NVarChar).Value = id_lang;
                SqlDataAdapter da = new SqlDataAdapter(comm);
                tblData = new DataTable();
                da.Fill(tblData);
            }
            catch
            {
                if (conn != null)
                {
                    conn.Close();
                    conn.Dispose();
                    conn = null;
                }
                return tblData;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                    conn.Dispose();
                    conn = null;
                }
            }

            return tblData;
        }


ALTER PROCEDURE usp_hienvd_tblang_getmenubylangid
	@id_lang int
AS
	select menu_id,title,depth
	from menuhorizal,tb_languages
	where menuhorizal.id_lang=tb_languages.id_lang and tb_languages.id_lang=@id_lang
	RETURN


我想在gridview中使用update/delete/insert命令或将超链接添加到gridview中的行标题中.但这是行不通的.请帮我解决问题.


我不认为使用数据集解决我的问题.除此之外,它的错误"ObjectDataSource" ObjectDataSource1"找不到具有参数:id_lang,menu_id,title,depth的非泛型方法"getmenulangid".当我单击更新按钮时.


I want to using update/delete/insert command with gridview or add hyperlink into row title in gridview. but it''s don''t work. please help me for problem.


I don''t think use dataset for my problem. beside that, It''s error "ObjectDataSource ''ObjectDataSource1'' could not find a non-generic method ''getmenulangid'' that has parameters: id_lang, menu_id, title, depth." when i click update''s button.

推荐答案

ConnectionStrings:ispaceconnectstring%>" SelectCommand = " </ asp:SqlDataSource > </ div > < asp:GridView ID = " runat = " CellPadding = " ForeColor = " GridLines = " Width = " 750px" AllowPaging = 真实" DataSourceID = " > < RowStyle BackColor = " ForeColor = " #333333" Height = 40px"/> < FooterStyle BackColor = " Font-Bold = " ForeColor = " " ForeColor = " #333333" Horizo​​ntalAlign = 居中" /> < SelectedRowStyle BackColor = " Font-Bold = " ForeColor = " Height = 30px"/> < HeaderStyle BackColor = " Font-Bold = " ForeColor = " Height = 50px"/> < AlternatingRowStyle BackColor = " /> </ asp:GridView > < asp:ObjectDataSource ID = " runat = " DeleteMethod = " InsertMethod = " getmenulangid" SelectMethod = " TypeName = " ispace.Class.cls_getmenubylangid" UpdateMethod = " > < DeleteParameters> < asp:参数名称= " Type = " /> </ DeleteParameters > < UpdateParameters> < asp:参数名称= " Type = " /> </ UpdateParameters > < SelectParameters> < asp:ControlParameter ControlID = " DefaultValue = " Name = " PropertyName = " Type = " Int32"/> </ SelectParameters > < InsertParameters> < asp:参数名称= " Type = " /> </ InsertParameters > </ asp:ObjectDataSource >
ConnectionStrings:ispaceconnectstring %>" SelectCommand="SELECT [id_lang], [languages] FROM [tb_languages]"> </asp:SqlDataSource> </div> <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#3E7C92" GridLines="None" Width="750px" AllowPaging="True" DataSourceID="ObjectDataSource1"> <RowStyle BackColor="#eff0f2" ForeColor="#333333" Height="40px" /> <FooterStyle BackColor="#f0f0f0" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#3e7c92" ForeColor="#333333" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#e5e5e5" Font-Bold="True" ForeColor="Navy" Height="30px" /> <HeaderStyle BackColor="#3e7c92" Font-Bold="True" ForeColor="White" Height="50px"/> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="getmenulangid" InsertMethod="getmenulangid" SelectMethod="getmenulangid" TypeName="ispace.Class.cls_getmenubylangid" UpdateMethod="getmenulangid"> <DeleteParameters> <asp:Parameter Name="id_lang" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="id_lang" Type="Int32" /> </UpdateParameters> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" DefaultValue="1" Name="id_lang" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="id_lang" Type="Int32" /> </InsertParameters> </asp:ObjectDataSource>


public DataTable getmenulangid(int id_lang)
        {
            SqlConnection mySqlConnection = new SqlConnection();// sql Product tra ve Product.ProductID=@ProductID

            SqlCommand mySqlCommand = new SqlCommand();
            DataTable tblData = new DataTable();
            // Khai báo câu truy vấn
            SqlConnection conn = new SqlConnection(Config.ispaceconnect);
            try
            {
                //OleDbConnection conObj = new OleDbConnection(connectString); 
                conn.Open();
                SqlCommand comm = new SqlCommand("usp_hienvd_tblang_getmenubylangid", conn);
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.Add("@id_lang", SqlDbType.NVarChar).Value = id_lang;
                SqlDataAdapter da = new SqlDataAdapter(comm);
                tblData = new DataTable();
                da.Fill(tblData);
            }
            catch
            {
                if (conn != null)
                {
                    conn.Close();
                    conn.Dispose();
                    conn = null;
                }
                return tblData;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                    conn.Dispose();
                    conn = null;
                }
            }

            return tblData;
        }


ALTER PROCEDURE usp_hienvd_tblang_getmenubylangid
	@id_lang int
AS
	select menu_id,title,depth
	from menuhorizal,tb_languages
	where menuhorizal.id_lang=tb_languages.id_lang and tb_languages.id_lang=@id_lang
	RETURN


我想在gridview中使用update/delete/insert命令或将超链接添加到gridview中的行标题中.但这是行不通的.请帮我解决问题.


我不认为使用数据集解决我的问题.除此之外,它的错误"ObjectDataSource" ObjectDataSource1"找不到具有参数:id_lang,menu_id,title,depth的非泛型方法"getmenulangid".当我单击更新"按钮时.


I want to using update/delete/insert command with gridview or add hyperlink into row title in gridview. but it''s don''t work. please help me for problem.


I don''t think use dataset for my problem. beside that, It''s error "ObjectDataSource ''ObjectDataSource1'' could not find a non-generic method ''getmenulangid'' that has parameters: id_lang, menu_id, title, depth." when i click update''s button.


我想给
<columns>
           <asp:hyperlinkfield datanavigateurlfields="menu_id" xmlns:asp="#unknown">
               DataNavigateUrlFormatString="updatemenu.aspx?menuid={0}" DataTextField="title"
               DataTextFormatString="{0}" HeaderText="Title" />
       </asp:hyperlinkfield></columns>

进入gridview.it找不到变量"menuid".有解决问题的办法吗?除此之外,我想在gridview中进行更新/删除/插入按钮模板...

into gridview.it don''t find variable "menuid". have a solution for about problem? Beside that, i want make update/delete/insert button template in gridview...


这篇关于帮助我使用带有存储过程的gridview吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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