Столбец шаблона сетки данных отправляется в .CSV - PullRequest
1 голос
/ 10 марта 2011

У меня есть GridView, который отлично экспортируется в .csv с кодом ниже.Проблема в том, что у меня есть TemplateColumn с TextBox, который вообще не записан в .CSV!

Может кто-нибудь помочь мне с этим ??это сводит меня с ума!

Любая помощь здесь будет отличной!

<asp:GridView ID="GridView1" runat="server" DataSourceID="as400" 
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" 
GridLines="None">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
 <asp:BoundField DataField="IMSKU" HeaderText="SKU"  />
 <asp:BoundField DataField="IMDESC" HeaderText="Description"  />
 <asp:BoundField DataField="JFFXQT" HeaderText="Required" 
    ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
    </asp:BoundField>
    <asp:TemplateField HeaderText="Qty"> 
    <ItemTemplate>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>

</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>

protected void Button1_Click(object sender, EventArgs e)
{

    //Get Username
string[] username = Request.ServerVariables["LOGON_USER"].ToString().Split('\\');
    globalfunctions getAttribute = new globalfunctions();

    string storeEmail = getAttribute.getADattribute(username[1], "mail");

    //append to csv file
    StreamWriter sw = File.AppendText("e:\\results\\decdiylayout.csv");

    //seperate datagrid to comma seperated values
     for (int i = 0; i < GridView1.Rows.Count; i++)
{
    string strRowVal = "";
    for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++)
    {
    if (strRowVal == "")
    {
        strRowVal = DateTime.Now + "," + username[1].Remove(3)+ "," + Layout.Text + "," + GridView1.Rows[i].Cells[j].Text;
    }
    else
    {
        strRowVal =  strRowVal + "," + GridView1.Rows[i].Cells[j].Text;
    }
    }
    sw.WriteLine(strRowVal);
}
sw.Close(); 

Ответы [ 2 ]

1 голос
/ 10 марта 2011

Это сработало:

         //append to csv file
         StreamWriter sw = File.AppendText("e:\\results\\decdiylayout.csv");

         //seperate datagrid to comma seperated values
         for (int i = 0; i < GridView1.Rows.Count; i++)
         {
            string strRowVal = "";
            for (int j = 0; j < GridView1.Rows[i].Cells.Count; j++)
            {

                GridViewRow row = GridView1.Rows[i];

                TextBox Qty = (TextBox)row.FindControl("TextBox2");
                String Quant = Qty.Text;


                if (strRowVal == "")
                {
                    strRowVal = DateTime.Now + "," + username[1].Remove(3)+ "," + Layout.Text + "," + Quant + "," + GridView1.Rows[i].Cells[j].Text;
                }
                else
                {
                    strRowVal =  strRowVal + "," + GridView1.Rows[i].Cells[j].Text;
                }
            }
            sw.WriteLine(strRowVal);
        }
        sw.Close(); 
0 голосов
/ 10 марта 2011

Вам нужно получить элемент управления textbox и получить его значение.

Что-то вроде ...

         TextBox txt = GridView1.Rows[i].Cells[j].FindControl("textboxid");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...