如何在GridView中处理多个命令域 [英] How to handle multiple commandfields in gridview

查看:80
本文介绍了如何在GridView中处理多个命令域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何在gridview中处理多个命令域.

我的aspx代码是:

Hi,
How to handle multiple commandfields in gridview.

My aspx code is:

<asp:GridView ID="GridOracle" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                        DataKeyNames="DIS_CHAPTER_ID" OnSelectedIndexChanged="GridOracle_SelectedIndexChanged"
                        BackColor="#CCCCCC" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="3px"
                        CellPadding="4" CellSpacing="2" ForeColor="Black">
                        <%-- BorderColor=#999999--%>
                        <Columns>
                            <asp:BoundField DataField="SEC_NAME" HeaderText="Section Name" ReadOnly="True" ItemStyle-HorizontalAlign="Left"
                                ItemStyle-Font-Bold="true" ItemStyle-VerticalAlign="Middle">
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Font-Bold="True"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="CHAPTER_NAME" HeaderText="CourseName" ReadOnly="True"
                                ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Middle">
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField DataField="Duration" HeaderText="Duration" ItemStyle-HorizontalAlign="Left"
                                ItemStyle-VerticalAlign="Middle">
                                <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle"></ItemStyle>
                            </asp:BoundField>
                            <asp:CommandField CausesValidation="False" InsertVisible="False" ShowCancelButton="False"
                                ButtonType="Image" ShowSelectButton="True" HeaderText="Material" ItemStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle" SelectImageUrl="~/Content/Images/PDFLogo.png">
                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                            </asp:CommandField>
                            <asp:CommandField  CausesValidation="False" InsertVisible="False" ShowCancelButton="False" 
                                ButtonType="Image" ShowSelectButton="True" HeaderText="Material1" ItemStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle" SelectImageUrl="~/Content/Images/PDFLogo.png">
                                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
                            </asp:CommandField>
                          </Columns>
                        <FooterStyle BackColor="#CCCCCC" />
                        <HeaderStyle BackColor="#CCCCCC" Font-Bold="True" ForeColor="Black" />
                        <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                        <RowStyle BackColor="White" />
                        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#808080" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#383838" />
                    </asp:GridView>



我的Commandpx的aspx.cs代码



My aspx.cs code for commandfield

protected void GridOracle_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (GridOracle.SelectedIndex > -1)
                {
                        this.Id = Convert.ToInt32(GridOracle.DataKeys[GridOracle.SelectedIndex].Value);
                        string _FName = "select FILE_NAME from OM_DOC_ALL where DIS_CHAPTER_ID = " + Id;
                        string _FileName = (string)SqlHelper.ExecuteScalar(strConn, CommandType.Text, _FName);
                        string FileName = "~/Downloads/OracleMaterial/" + _FileName + ".pdf";
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
                        WebClient client = new WebClient();
                        string pdfPath = Server.MapPath("../Downloads/OracleMaterial/" + _FileName + ".pdf");
                        Byte[] buffer = client.DownloadData(pdfPath);
                        BinaryWriter bw = new BinaryWriter(Response.OutputStream);
                        bw.Write(buffer);
                        bw.Close();
                        Response.ContentType = "application/pdf";
                        Response.Flush();
                        Response.Close();
                    
                }
                else
                {
                    //Clear Controls
                }
            }
            catch (Exception ex)
            {
                ErrorHandling.ErrorLog("PageLoad: ExploreJobs.aspx.cs ,  Error : " + ex.Message);
            }
        
        
    }




如何编写2个命令域(材料和材料1"的标题文本)代码.




How to write 2 commandfields(Header text of Material & Material1) code.

推荐答案

此处: ^ ]

如果需要,只需Google/Bing即可!
Here: Using CommandField in a GridView control[^]

If needed, just Google/Bing for more!


请参阅:

http://bytes.com/topic/asp-net/answers/441800-asp-net-2-0-problem-gridview-2-commandfields [ http://forums.asp.net/t/1795862.aspx/1?如何+处理+多个+命令字段+ in + gridview [
Refer this:

http://bytes.com/topic/asp-net/answers/441800-asp-net-2-0-problem-gridview-2-commandfields[^]

http://forums.asp.net/t/1795862.aspx/1?How+to+handle+multiple+commandfields+in+gridview[^]



尝试访问以下链接:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandfield.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx [ http://forums. asp.net/t/1004468.aspx/1?处理+命令+事件+动态+已添加+ LinkBut​​tons + in + a + GridView [
Hi,
Try visiting these links:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandfield.aspx[^]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx[^]
http://forums.asp.net/t/1004468.aspx/1?Handling+Command+Events+for+Dynamically+Added+LinkButtons+in+a+GridView[^]
It may help you..


这篇关于如何在GridView中处理多个命令域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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