Note that there are some explanatory texts on larger screens.

plurals
  1. POGrid view Row Data Bound putting data in a particular cell
    primarykey
    data
    text
    <p>I have 3 tables <code>Customer</code>, <code>Address</code> and <code>Matching_Customer_Address</code>. </p> <p><code>Customer</code> has column <code>Name</code> and <code>Address</code> has column <code>City</code>. They have some other columns as well but I don't need them. The <code>Name</code> and the <code>City</code> column contains this kind of data. </p> <pre><code> NAME City ---------- ----------- John New York ---------- ---------- Karin Hamburg --------- ---------- Jona Tokyo --------- ---------- Martin </code></pre> <p><code>Matching_Customer_Address</code> contains the IDs of both tables which have a match between them. </p> <p>I have a Grid view and I bind this <code>GridView1</code> with datatable <code>dt</code>. dt is in this format: Data table dt first column is "Match" and rest of the columns are from <code>Address.City</code> and rows are from <code>Customer.Name</code>. </p> <p>As Gridview1 is bind with dt so grid view is like this. </p> <pre><code>Match | New York| Hamburg | Tokyo | ----- | --------| ------- | ------ | John | | | | ----- | ------- | ------- | ------ | Karin | | | | ----- | ------- | ------- | ------ | Jona | | | | ----- | ------- | ------- | ------ | Martin| | | | ----- | ------- | ------- | ------ | </code></pre> <p>Now by using the table <code>Matching_Customer_Address</code> I want to put a character "X" in <code>GridView1</code> cell. I am using <code>RowDataBound</code> event to do this task but I don't know how I should proceed. </p> <p>I am trying to do</p> <pre><code> e.Row.Cells[].Text = "X"; </code></pre> <p>I know how to access the <code>Matching_Customer_Address</code> table here But I don't know how to put an X in a particular cell if a match is found. I am very new to C#. </p> <p>Here is the code to bind data with gridview. </p> <pre><code>DataTable dt = new DataTable(); SqlDataAdapter da_Customer, da_Address; DataSet ds_Customer = new DataSet(); DataSet ds_Address = new DataSet(); SqlConnection con; con = new SqlConnection("Data Source=local;Initial Catalog=Test;Integrated Security=True"); da_Customer= new SqlDataAdapter("Select Name from Customer ", con); da_Customer.Fill(ds_Customer, "Name"); da_Address = new SqlDataAdapter("Select City from Address ", con); da_Address .Fill(ds_Address, "City"); int lengthofAddress = ds_Address.Tables[0].Select("City is not null").Length; string[] getCols_City = new string[lengthofAddress]; int lengthofCustomer = ds_Customer.Tables[0].Select("Customer is not null").Length; string[] getRows_Customer = new string[lengthofCustomer]; //added first column of dt. dt.Columns.Add(new DataColumn("Name", typeof(string))); // This loop is getting rows from table City and adding them as column of dt. for (int x = 0; x &lt; (lengthofAddress); x++) { string mystring = (ds_Address.Tables[0].Rows[x]["City"].ToString()); getRows_Customer[x] = mystring; dt.Columns.Add(getRows_Customer[x]); } // This loop is getting rows from table Customer and adding them as Rows of dt. for (int x = 0; x &lt; (lengthofCustomer); x++) { getRows_Customer[x] = (ds_Customer.Tables[0].Rows[x]["Name"].ToString()); dt.Rows.Add(getRows_Customer[x]); } GridView1.DataSource = dt; GridView1.DataBind(); </code></pre> <p>Aspx Code is here :</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#3366CC" BorderWidth="1px" CellPadding="4" Font-Names="Arial" Font-Size="Small" Width="100%" BorderStyle="None" OnRowEditing="GridView1_RowEditing" onrowdatabound="GridView1_RowDataBound" &gt; &lt;HeaderStyle CssClass="GridviewScrollHeader" /&gt; &lt;RowStyle CssClass="GridviewScrollItem" /&gt; &lt;PagerStyle CssClass="GridviewScrollPager" /&gt; &lt;/asp:GridView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload