gpt4 book ai didi

c# - 无法从列表中获取值以便设置网格 header 值 c#

转载 作者:太空宇宙 更新时间:2023-11-03 22:51:40 25 4
gpt4 key购买 nike

我正在尝试从出现错误的列表中设置网格 header 值

Object Reference not set to an instance of an object

我先检查了它,但我正在将列表值转换为字符串,在调试时我可以在列表中找到值

代码如下,

        List<string> rows = new List<string>(
new string[] { "Item", "Quantity", "Price" });

GdItemList.HeaderRow.Cells[0].Text = Convert.ToString(rows[0]);
GdItemList.HeaderRow.Cells[1].Text = rows[1].ToString();
GdItemList.HeaderRow.Cells[2].Text = rows[2].ToString();

GdItemList GridView 就像,

<asp:GridView ID="GdItemList" runat="server" ShowHeaderWhenEmpty="True" CellPadding="4"
EmptyDataText="No Record Found" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>

最佳答案

List<string> rows = new List<string>(
new string[] { "Item", "Quantity", "Price" });

GdItemList.Columns[0].HeaderText = Convert.ToString(rows[0]);
GdItemList.Columns[1].HeaderText = rows[1].ToString();
GdItemList.Columns[2].HeaderText = rows[2].ToString();

关于c# - 无法从列表中获取值以便设置网格 header 值 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47108817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com