Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to :hyperlinkcolumn in string array

Status
Not open for further replies.

edelwater

Programmer
Jun 29, 2000
203
EU
Simple question:

i define an array :
Code:
subdir = System.IO.Directory.GetDirectories("\\bla\\");
        string CorrectString;
        testGrid1.DataSource = subdir;
        testGrid1.DataBind();

i define a datagrid :

Code:
<asp:datagrid id="testGrid1" runat="server" AutoGenerateColumns="False" EnableViewState="False">
                                <Columns>
                                    <asp:HyperLinkColumn HeaderText="Test" DataNavigateUrlField="subdir" DataNavigateUrlFormatString="relreq.aspx?id={0}"/>
                                </Columns>
                            </asp:datagrid>

Why does it give me the error :

Code:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: A field or property with the name 'subdir' was not found on the selected datasource.

????



--
 
edelwater,
the best way to handle this case as create a datatable and populate it from your array
the following code should work for you

Code:
private void Page_Load(object sender, System.EventArgs e)
{
string [] subdir = System.IO.Directory.GetDirectories(Server.MapPath("/TestCsharp/"));
	DataTable dt=new DataTable();
	DataRow dr;
	dt.Columns.Add(new DataColumn("Directory",typeof(string)));

foreach (string str in subdir)
{
			
       dr=dt.NewRow();
       dr[0]=str;
       dt.Rows.Add(dr);
}
testgrid1.DataSource =new DataView(dt);
testgrid1.DataBind();
}

HTML Code should be like
Code:
<asp:datagrid id="testgrid1" runat="server" autoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Directory" DataNavigateUrlFormatString="relreq.aspx?id={0}"DataTextField="Directory" HeaderText="Directory"></asp:HyperLinkColumn>
</Columns>
</asp:datagrid>

Hope that helps
Good luck


What would you attempt to accomplish if you knew you would not fail?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top