c#

2016-04-25 1 views
0

を使用して、GridviewのItemtemplateにテキストをバインドする問題があります。フォルダへのパスウェイを含む長いテキストをC#で読み取る方法があります。正規表現を使用してそれを分解することで、私は私のgridviewに表示したい小さなテキストを保存します。コードは、このc#

string folder = @"X:\05_General\T\TestVehicleInfo\Vehicles\Bordeaux_2099908\Readouts\All\20160126_22138km_RESF_Tw1602\After\XCOM\Bordeaux_2099908_20160128_22159km_XCOM_ALL_DTC_CDABX1.txt"; 
     string[] parts = folder.Split('\\'); 
     List<string> filteredstrings = new List<string>(); 
     foreach (string part in parts) 
     { 
      if (Regex.IsMatch(part, @"\d{8}")) 
      { 
       filteredstrings.Add(part); 
      } 
     } 

のように見え、GridViewのは、次のようになります

<asp:BoundField DataField="ReadOutID" HeaderText="ReadOutID" InsertVisible="False" ReadOnly="True" SortExpression="ReadOutID" /> 
           <asp:BoundField DataField="FileName" HeaderText="FileName" SortExpression="FileName" /> 
           <asp:BoundField DataField="FileTime" HeaderText="FileTime" SortExpression="FileTime" /> 
           <asp:BoundField DataField="ImportTime" HeaderText="ImportTime" SortExpression="ImportTime" /> 
           <%-- <asp:BoundField DataField="FullPath" HeaderText="Comment" SortExpression="FullPath" />--%> 
           <asp:TemplateField HeaderText="Comment" SortExpression="FullPath"> 
            <EditItemTemplate> 
             <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FullPath") %>'></asp:TextBox> 

            </EditItemTemplate> 
            <ItemTemplate> 
             <asp:Label ID="Label1" runat="server" Text='<%# **What should i write here?** %>'></asp:Label> 


            </ItemTemplate> 

私はASPでfilteredstingを表示したい:私は「私はここで何を書くべき」を書いたラベル領域。私はどんなコマンドを使うべきですか?

+0

を助けることを願っています

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string folder = e.Row.Cells[1].Text;//Your gridview cell location of that string string[] parts = folder.Split('\\'); List<string> filteredstrings = new List<string>(); foreach (string part in parts) { if (Regex.IsMatch(part, @"\d{8}")) { filteredstrings.Add(part); } } e.Row.Cells.Add(new TableCell() {Text = string.Join(",", filteredstrings)});// this will give CSV value of your List<string> } } 
の後ろのコードにこのコードを試してみてください、あなたはASPX上ごGridview行 でその文字列を持っていると仮定あなたは 'DataTable'からgridviewを満たしていますか? – KanisXXX

+0

はい! SQLソースから –

+0

あなたはグリッドビューに表示したいリストを持っているので、右ですか? – KanisXXX

答えて

0

私はその後、GridViewの

OnRowDataBound="GridView1_OnRowDataBound"イベントを追加し、これが

+0

ありがとうございました!これは私の問題を解決しました。 –

+0

私は助けてくれたことをうれしく思っています。 – KanisXXX